TypeScript Playground isn't a fully fledged sandbox solution. It's merely meant as a simple type explorer that doesn't need dependencies.

For your use case I would recommend using CodeSandbox instead. It comes with a whole bunch of TypeScript templates to choose from when creating a sandbox. TypeScript Playground also has an export menu where you can open your code in CodeSandbox directly.

The UI is based off of VS Code, so if you're used to that you will feel just at home.

Answer from mekwall on Stack Overflow
🌐
GitHub
github.com › agneym › playground
GitHub - agneym/playground: A simple playground for HTML, CSS and JavaScript supporting module imports.
import Playground from "@agney/playground"; const App = () => { const snippet = { markup: `<div id=app />`, css: ``, javascript: `import React, { createElement } from "https://cdn.skypack.dev/react"; import ReactDOM from "https://cdn.skypack.dev/react-dom"; ReactDOM.render( <h1>Hello World</h1>, document.getElementById("app") );`, }; return ( <Playground initialSnippet={snippet} defaultEditorTab="javascript" transformJs presets={["react"]} /> ); };
Starred by 1.1K users
Forked by 159 users
Languages   TypeScript 93.9% | JavaScript 3.4% | HTML 2.4% | Shell 0.3%
🌐
RunJS
runjs.app
RunJS - JavaScript and TypeScript Playground for macOS, Windows and Linux
This. is. awesome: RunJS, a JavaScript playground for Mac. Supports TypeScript, Babel transpilation, Node and browser APIs altogether, import Node modules from a folder, and more.
🌐
TypeScript
typescriptlang.org › play › javascript › modern-javascript › import-export.ts.html
TypeScript: Playground Example - Import Export
import debug from "debug"; const log = debug("playground"); log("Started running code"); // Because of the nature of default exports having no true name, they can be tricky when applied with static analysis tools like the refactoring support in TypeScript but they have their uses. Because there is a long history in importing/exporting code in JavaScript, there is a confusing part of default exports: Some exports have documentation that implies you can write an import like this:
🌐
Playcode
playcode.io
JavaScript Playground - Free Online JS Sandbox
PlayCode is the #1 JavaScript Playground trusted by millions of developers worldwide. Write, run, and test your JavaScript code instantly in your browser, no setup, no installation required. A complete JS sandbox with live preview. Import npm packages with a single line.
🌐
GitHub
github.com › dabbott › javascript-playgrounds
GitHub - dabbott/javascript-playgrounds: An interactive JavaScript sandbox
This project provides a quick, visual way to experiment with JavaScript code. It's designed to be loaded as an iframe for easy inclusion in any webpage. There are a variety of configuration options, including a React preset and a React Native preset.
Starred by 1.4K users
Forked by 131 users
Languages   TypeScript 95.7% | JavaScript 2.5% | CSS 1.7% | EJS 0.1%
🌐
GitHub
github.com › gmh5225 › HTML-playground
GitHub - gmh5225/HTML-playground: A simple playground for HTML, CSS and JavaScript supporting module imports.
import Playground from "@agney/playground"; const App = () => { const snippet = { markup: `<div id=app />`, css: ``, javascript: `import React, { createElement } from "https://cdn.skypack.dev/react"; import ReactDOM from "https://cdn.skypack.dev/react-dom"; ReactDOM.render( <h1>Hello World</h1>, document.getElementById("app") );`, }; return ( <Playground initialSnippet={snippet} defaultEditorTab="javascript" transformJs presets={["react"]} /> ); };
Author   gmh5225
Top answer
1 of 4
23

TypeScript Playground isn't a fully fledged sandbox solution. It's merely meant as a simple type explorer that doesn't need dependencies.

For your use case I would recommend using CodeSandbox instead. It comes with a whole bunch of TypeScript templates to choose from when creating a sandbox. TypeScript Playground also has an export menu where you can open your code in CodeSandbox directly.

The UI is based off of VS Code, so if you're used to that you will feel just at home.

2 of 4
5

If by "importing" you mean using import to include an npm package that can be accessed at runtime, that is not a feature of the TypeScript Playground, unfortunately; it's intended for testing features of the language and the compiler.

You'll need to use a sandbox environment if you want to include npm packages, bundlers, etc.; checkout CodeSandbox, as others have suggested.


About your particular error:

[ERR]: Executed JavaScript Failed:
[ERR]: Cannot use import statement outside a module

This is due to your current configuration, not the lack of package support by TypeScript Playground. By default, your .js output probably looks something like this:

import * as _ from "underscore";
const equalResult = _.isEqual('ABC', '123');

This is because the default module setting in the Playground is set to ESNext.

If we change this to CommonJS for example, we get:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? 

// A bunch more lines .....

const _ = __importStar(require("underscore"));
const equalResult = _.isEqual('ABC', '123');

Now we get another error that tells us explicitly that our package is unavailable:

[ERR]: "Executed JavaScript Failed:" 
[ERR]: Check dependency list! Synchronous require cannot resolve module 'underscore'. 
       This is the first mention of this module! 

While the playground is smart enough to auto-import the types for import statements, it doesn't support external modules outside of this.

🌐
Quokkajs
quokkajs.com
Quokka - JavaScript and TypeScript playground in your editor
Unlike online REPL tools and standalone playgrounds, Quokka runs your JavaScript code in VS Code, WebStorm, or Sublime, so you can avoid context switching while benefiting from your familiar editor environment and its extensions. You can also import and run files and modules from your project. Quokka 'Community' edition is free for everyone, brought to you with love by the Wallaby.js team.
🌐
Playcode
playcode.io › new
JavaScript Playground
PlayCode is the #1 JavaScript Playground trusted by millions of developers worldwide. Write, run, and test your JavaScript code instantly in your browser, no setup, no installation required. A complete JS sandbox with live preview. Import npm packages with a single line.
Find elsewhere
🌐
npm
npmjs.com › package › playground-elements
playground-elements - npm
The main playground-elements import loads all Playground elements, but when making a custom layout it's a good idea to only load the sub-components you're actually using. This will make your JavaScript bundle smaller.
      » npm install playground-elements
    
Published   Oct 02, 2025
Version   0.21.2
Author   Google LLC
🌐
npm
npmjs.com › package › javascript-playgrounds
javascript-playgrounds - npm
This project provides a quick, visual way to experiment with JavaScript code. It's designed to be loaded as an iframe for easy inclusion in any webpage. There are a variety of configuration options, including a React preset and a React Native preset.
      » npm install javascript-playgrounds
    
🌐
Krasimirtsonev
krasimirtsonev.com › blog › article › build-your-own-interactive-javascript-playground
Build your own interactive JavaScript playground
I guess you will agree with me if I say that the majority of JavaScript that we write today requires transpilation. I decided to use Babel. Not because it is the most popular transpiler but because it offers a client-side standalone processing. This means that we can import babel.js on our page and we will be able to transpile code on the fly.
🌐
npm
npmjs.com › package › @ui-js › code-playground
@ui-js/code-playground - npm
the path of import directives can be modified as well. Add a <script> tag inside the component that defines a moduleMap variable that maps a module name to a URL. For example: <code-playground> <script> moduleMap = { mathlive: "//unpkg.com/mathlive/dist/mathlive.min.mjs", }; </script></code-playground> <div slot="javascript">import MathLive from 'mathlive';</div> </code-playground>
      » npm install @ui-js/code-playground
    
Published   Jul 16, 2025
Version   1.12.0
🌐
Jsrepl
jsrepl.io
JavaScript REPL & Playground
Just import them in the code. There is no step 2. Types included. ... We live in modern times, don't we? Tailwind CSS is enabled by default. IntelliSense included. ... Because you shouldn't waste time on formatting while prototyping. ... Prototype dynamic UIs with React and JSX, experiment with reactivity. ... No login / registration required. I mean it works right in your browser. The playground powered by client-side JavaScript and WebAssembly.
🌐
DEV Community
dev.to › sonicoder › the-online-javascript-playground-that-will-blow-your-mind-58ic
The online Javascript playground that will blow your mind - DEV Community
November 15, 2019 - ... The project that surprised and me and has the above features is Codesandbox. Codesandbox lets you import your Github projects or start a new React, Angular, Vue application generated by their CLIs. It just works and boots fast.
🌐
Souporserious
souporserious.com › build-your-own-code-playground
Build Your Own Code Playground | souporserious
We must compile our code at runtime since we want to write imports and exports with other modern JavaScript. This is similar to what we would need in a build step for a library or application. We’ll use SWC to accomplish this, a performant compiler we can use to transpile our code for the browser. We’ll use the official playground ...
🌐
Playcode
playcode.io › javascript-compiler
JavaScript Compiler - AI-Powered JS Compiler Online | Free
Unlike traditional compilers that produce machine code, JS compilers like PlayCode bundle your code, resolve imports, and transpile modern syntax (ES2026, TypeScript, JSX) into browser-compatible JavaScript that runs instantly. Yes, PlayCode's JavaScript compiler is completely free to use. ...
🌐
JSFiddle
jsfiddle.net
JSFiddle - Code Playground
Debug your Fiddle with a minimal built-in JavaScript console.
🌐
DEV Community
dev.to › boywithsilverwings › introducing-playground-1cko
Introducing Playground - A Frontend Demonstration Component - DEV Community
December 1, 2019 - import Playground from "@agney/playground"; const App = () => { const snippet = { markup: `<div id=app />`, css: ``, javascript: `import React, { createElement } from "@pika/react"; import ReactDOM from "@pika/react-dom"; ReactDOM.render( <h1>Hello World</h1>, document.getElementById("app") );`, }; return ( <Playground initialSnippet={snippet} defaultEditorTab="javascript" transformJs presets={["react"]} /> ); };
🌐
TypeScript
typescriptlang.org › play
TypeScript: TS Playground - An online editor for exploring TypeScript and JavaScript
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.