Understand Sucrase limitations and use cases
mainSucrase is designed for speed and is primarily intended for development environments targeting modern runtimes. Before using it, be aware of the following limitations:
- No Error Checking: Sucrase does not check your code for errors. It assumes the input is valid. Always use a linter or typechecker (like ESLint or TypeScript) alongside Sucrase.
- Not Pluginizable: Unlike Babel, you cannot easily add custom transforms.
- No ES5 Support: Sucrase will not compile code down to ES5 for old browsers like IE.
- No Typechecking: Sucrase processes files in isolation. It cannot perform cross-file type analysis (e.g., TypeScript
const enums are treated as regularenums). - Production Use: While usable, Babel or
tscare often more suitable for production builds. Sucrase is most beneficial in development to speed up build steps.