{"id":20587,"library":"sucrase","title":"Sucrase","description":"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.","status":"active","version":"3.35.1","language":"javascript","source_language":"en","source_url":"https://github.com/alangpierce/sucrase","tags":["javascript","babel","jsx","typescript","flow"],"install":[{"cmd":"npm install sucrase","lang":"bash","label":"npm"},{"cmd":"yarn add sucrase","lang":"bash","label":"yarn"},{"cmd":"pnpm add sucrase","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"TypeScript types rely on Node types","package":"@types/node","optional":true}],"imports":[{"note":"Named export; no default export.","wrong":"import sucrase from 'sucrase'","symbol":"transform","correct":"import { transform } from 'sucrase'"},{"note":"CommonJS require hook; ESM import may not work as expected.","wrong":"import 'sucrase/register'","symbol":"sucrase/register","correct":"require('sucrase/register')"},{"note":"Internal module; not part of public API.","wrong":"import { getFormatted } from 'sucrase'","symbol":"getFormatted","correct":"import { getFormatted } from 'sucrase/dist/parser'"}],"quickstart":{"code":"import { transform } from 'sucrase';\nimport * as fs from 'fs';\n\nconst code = fs.readFileSync('input.ts', 'utf8');\nconst result = transform(code, {\n  transforms: ['typescript', 'imports'],\n  filePath: 'input.ts',\n});\nconsole.log(result.code);","lang":"typescript","description":"Read a TypeScript file, remove type annotations, and convert ES modules to CommonJS."},"warnings":[{"fix":"Consider using Node.js --loader or --experimental-loader flags with a custom hook.","message":"Using `sucrase/register` for dynamic require hooks may be deprecated in favor of official Node.js loader hooks.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Enable TypeScript's `isolatedModules` flag to disallow `const enum`s.","message":"TypeScript enums: Sucrase compiles enums but does not support `const enum`s that rely on cross-file inlining.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Use `sourceMaps` and `sourceMapUrl` options instead. Upgrade to Node >=14.17.","message":"v3 dropped support for Node.js versions <14.17 and removed some legacy options like `sourceMap` and `sourceMapTarget`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use `jsxRuntime: 'automatic'` and add `jsxImportSource` or ensure React is globally available.","message":"JSX transform: Default runtime is `classic` (React.createElement). Some users encounter 'React is not defined' errors if not importing React.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use require('sucrase/register') or check that sucrase is installed as a devDependency.","cause":"Import path typo or incorrect module resolution.","error":"Cannot find module 'sucrase/register'"},{"fix":"Preprocess decorators with a separate tool like Babel or use a TypeScript transformer.","cause":"Sucrase does not support decorators (neither legacy nor TC39).","error":"Unsupported transform: decorators"},{"fix":"Run tsc separately or use the `--noEmit` flag for type checking before Sucrase.","cause":"Sucrase removes types but does not validate TypeScript; you still need `tsc` for type checking.","error":"TypeScript error: Cannot use namespace 'Foo' as a type."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}