Registry / serialization / sandpack-transpiler

sandpack-transpiler

JSON →
library0.3.2jsnpmunverified

A highly optimized transpiler for JSX, CJS, and ESM, built for the Sandpack ecosystem and based on Sucrase. Version 0.3.2 (pre-stable) ships TypeScript types, requires Node >=16, and focuses on performance, claiming >1M lines/sec on benchmarks. It is designed specifically for in-browser transpilation in sandboxed environments, distinguishing itself from general-purpose transpilers like Babel, esbuild, and swc by targeting Sandpack's use cases with minimal overhead. Currently in active development with no stable release.

npm install sandpack-transpiler
INSTALL
IMPORT
SIG · SANDPACK-TRANSPILE
S
sandpack-transpiler
serializationjavascriptv0.3.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transpile
import { transpile } from 'sandpack-transpiler'
const transpile = require('sandpack-transpiler').transpile
ESM-only; CJS require not supported.
transpileWithSucrase
import { transpileWithSucrase } from 'sandpack-transpiler'
import { transpileWithSucrase } from 'sandpack-transpiler/transpilers'
Named export, not a default export.
default
import SandpackTranspiler from 'sandpack-transpiler'
const SandpackTranspiler = require('sandpack-transpiler').default
Default export is the main transpiler class; ESM only.

Transpile a simple ESM module using the default React preset. The result is ESNext with JSX compiled.

import { transpile } from 'sandpack-transpiler'; const code = `const x = 1; export default x;`; transpile(code, { filePath: '/App.js', preset: 'react', }).then((result) => { console.log(result.code); // Output: "var x = 1; export default x;" });
Debug
Known issues
breakingVersion 0.3.x removed the 'transform' export; use 'transpile' instead.
fix
Replace `import { transform } from 'sandpack-transpiler'` with `import { transpile } from 'sandpack-transpiler'`.
affects: >=0.3.0
gotchaAll exports are async; calling transpile without await will return a Promise.
fix
Always `await transpile(...)` or chain `.then()`.
affects: >=0.1.0
deprecatedThe 'preset' option in transpile is deprecated; use 'transforms' instead.
fix
Use `transforms: ['jsx', 'imports']` instead of `preset: 'react'`.
affects: >=0.2.0 <0.3.0
gotchaNode.js >=16 required; earlier versions will throw an error due to top-level await usage.
fix
Upgrade Node.js to version 16 or later.
affects: >=0.1.0
breakingVersion 0.2.0 changed the default export from a function to a class.
fix
Use `new SandpackTranspiler()` and call `.transpile()` method, or import `{ transpile }` instead.
affects: >=0.2.0
Errors
Common errors & fixes
Error: The preset option is no longer supported. Use transforms instead.
Using deprecated `preset` property in options.
fix
Replace `{ preset: 'react' }` with `{ transforms: ['jsx', 'imports'] }`.
TypeError: sandpackTranspiler is not a constructor
Importing the package as an ES module and trying to use `new` on a default import when the default is not a class.
fix
Use `import { transpile } from 'sandpack-transpiler'` and call it as a function.
SyntaxError: Cannot use import statement outside a module
Running ES module import syntax in a CommonJS context.
fix
Ensure package.json has `"type": "module"` or use `.mjs` extension.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies
sucraserequiredcore transpilation logic derived from Sucrase
Agent activity
4 hits · last 30 days
node
4
Resources
sandpack-transpiler — npm install sandpack-transpiler · libregistry