Registry / web-framework / sucrase

sucrase

JSON →
library3.35.1jsnpmunverified

Sucrase v3.35.1 is a super-fast JavaScript/TypeScript transpiler focused on modern JS runtimes. Unlike Babel or TypeScript, it only compiles non-standard language extensions (JSX, TypeScript, Flow) and ES modules to CommonJS, offering ~20x speed improvement. It ships TypeScript types, requires Node >=16 or 14.17+, and is actively maintained on GitHub. Primarily used for development builds where type checking is handled separately.

npm install sucrase
INSTALL
IMPORT
SIG · SUCRASE
S
sucrase
web-frameworkjavascriptv3.35.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

transform
import { transform } from 'sucrase'
import sucrase from 'sucrase'
Named export; no default export.
sucrase/register
require('sucrase/register')
import 'sucrase/register'
CommonJS require hook; ESM import may not work as expected.
getFormatted
import { getFormatted } from 'sucrase/dist/parser'
import { getFormatted } from 'sucrase'
Internal module; not part of public API.

Read a TypeScript file, remove type annotations, and convert ES modules to CommonJS.

import { transform } from 'sucrase'; import * as fs from 'fs'; const code = fs.readFileSync('input.ts', 'utf8'); const result = transform(code, { transforms: ['typescript', 'imports'], filePath: 'input.ts', }); console.log(result.code);
Debug
Known issues
deprecatedUsing `sucrase/register` for dynamic require hooks may be deprecated in favor of official Node.js loader hooks.
fix
Consider using Node.js --loader or --experimental-loader flags with a custom hook.
affects: >=3.0.0
gotchaTypeScript enums: Sucrase compiles enums but does not support `const enum`s that rely on cross-file inlining.
fix
Enable TypeScript's `isolatedModules` flag to disallow `const enum`s.
affects: >=3.0.0
breakingv3 dropped support for Node.js versions <14.17 and removed some legacy options like `sourceMap` and `sourceMapTarget`.
fix
Use `sourceMaps` and `sourceMapUrl` options instead. Upgrade to Node >=14.17.
affects: >=3.0.0
gotchaJSX transform: Default runtime is `classic` (React.createElement). Some users encounter 'React is not defined' errors if not importing React.
fix
Use `jsxRuntime: 'automatic'` and add `jsxImportSource` or ensure React is globally available.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'sucrase/register'
Import path typo or incorrect module resolution.
fix
Use require('sucrase/register') or check that sucrase is installed as a devDependency.
Unsupported transform: decorators
Sucrase does not support decorators (neither legacy nor TC39).
fix
Preprocess decorators with a separate tool like Babel or use a TypeScript transformer.
TypeScript error: Cannot use namespace 'Foo' as a type.
Sucrase removes types but does not validate TypeScript; you still need `tsc` for type checking.
fix
Run tsc separately or use the `--noEmit` flag for type checking before Sucrase.
Upgrade
Version history
3.35.1latest on npm
Audit
Dependencies
@types/nodeoptionalTypeScript types rely on Node types
Agent activity
6 hits · last 30 days
node
6
Resources
sucrase — npm install sucrase · libregistry