Registry / web-framework / esm-compiler

esm-compiler

JSON →
library0.9.2jsnpmunverified

ESM Compiler is a Rust-based compiler for the esm.sh playground, leveraging swc for JavaScript/TypeScript/JSX transformation and lightningcss for CSS. Built as a WebAssembly module, it compiles modern frontend code into ESM-compatible output with import maps. Version 0.9.2 is the current stable release; it is actively developed as part of the esm.sh ecosystem. Key differentiators include its Wasm-first architecture, Rust performance, and tight integration with esm.sh's import map resolution, making it suitable for in-browser code transformation without a server.

npm install esm-compiler
INSTALL
IMPORT
SIG · ESM-COMPILER
E
esm-compiler
web-frameworkjavascriptv0.9.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.

init
import init, { transform } from 'https://esm.sh/esm-compiler'
const init = require('esm-compiler')
This is an ESM package loaded via URL (esm.sh). init() must be called to load the Wasm module before using transform.
transform
import { transform } from 'https://esm.sh/esm-compiler'
import transform from 'esm-compiler'
transform is a named export, not default. Must be destructured from the module.
TransformOptions
import type { TransformOptions } from 'https://esm.sh/esm-compiler'
import { TransformOptions } from 'esm-compiler'
TransformOptions is a TypeScript type and should be imported using import type for runtime efficiency in bundlers.

Initializes the Wasm compiler, transforms a React JSX component with an import map, and logs the compiled ESM output.

import init, { transform } from 'https://esm.sh/esm-compiler@0.9.2'; await init(); const code = ` import { useState } from "react"; export default function App() { const [msg] = useState("world"); return <h1>Hello {msg}!</h1>; } `; const importMap = { imports: { "@jsxImportSource": "https://esm.sh/react@18", "react": "https://esm.sh/react@18" } }; const result = transform('./App.tsx', code, { importMap }); console.log(result.code);
Debug
Known issues
breakinginit() must be called before any transform call
fix
Ensure init() is awaited once at the start of your application.
affects: all
breakingVersion 0.9.x changed import resolution to require full URL imports
fix
Use the full esm.sh URL (https://esm.sh/esm-compiler) instead of a local or npm import.
affects: >=0.9.0
deprecatedThe previous synchronous transform API is deprecated
fix
Use the async transform function returned after init().
affects: >=0.9.0
gotchaTypeScript types are only exported as type-only; cannot be used as runtime values
fix
Use 'import type { ... }' for type imports to avoid bundling errors.
affects: all
gotchaimportMap.imports must include '@jsxImportSource' for JSX to work correctly
fix
Always specify the JSX import source in the import map imports object.
affects: all
Errors
Common errors & fixes
Error: transform is not a function
init() was not called or the Wasm module failed to load
fix
Call await init() before calling transform, and check network requests for the .wasm file.
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '__wbg_...')
Calling transform before init() has completed
fix
Wrap your transform calls in an async function and ensure init() is awaited.
Module parse failed: Unexpected token (10:20) You may need an appropriate loader to handle this file type.
Bundler (e.g., webpack) cannot handle Wasm blob URL or ES module imports from esm.sh
fix
Use a bundler like Vite or configure webpack to support WebAssembly and esm.sh imports.
Upgrade
Version history
0.9.2latest on npm
Audit
Dependencies
swcrequiredJavaScript/TypeScript/JSX transformation engine
lightningcssrequiredCSS minification and transformation
Agent activity
2 hits · last 30 days
node
2
Resources
esm-compiler — npm install esm-compiler · libregistry