Sucrase rivals Babel JavaScript compiler for development use

Not recommended for production, Sucrase trades the scope and flexibility of Babel for faster builds during development

Sucrase rivals Babel JavaScript compiler for development use
Thinkstock

The speedy Sucrase compiler is emerging as a potential alternative to the Babel JavaScript compiler for development purposes, if not for production builds. The developers behind the project claim that Sucrase is much faster than Babel, while acknowledging that it lacks Babel’s scope and versatility. 

Sucrase is intended to make programming more fun by making builds faster. Sucrase assumes a developer is using a recent browser or a recent version of Node.js. Thus, it focuses on compiling non-standard language extensions such as TypeScript, Flow, and JSX. This narrower scope enables leveraging of a compiler architecture that is much more performant, albeit less extensible and maintainable. As a result, developers are advised to think carefully about using Sucrase in production. Babel or tsc is more suitable for production builds in most cases. 

The Sucrase parser is a trimmed-down fork of the Babel parser that focuses on a subset of what is addressed by Babel. The main configuration option in Sucrase is an array of transform names including jsx, typescript, flow, and react-hot-loader. Some JavaScript syntax such as decorators and private fields are not supported by Sucrase but passed through, so must be supported by the developer’s JavaScript runtime.

The creators of Sucrase also cite these limitations:

  • Sucrase does not check code for errors and should always be used with a linter or typechecker.
  • Sucrase does not leverage plug-ins. Transforms need to be written to cooperate with each other; each additional transform takes significant work. 
  • The tool is not good for prototyping language extensions and upcoming language features. The faster architecture of Sucrase makes new transforms more fragile and more difficult to write.

You can install Sucrase via yarn or npm. Installation instructions and documentation are provided in the Sucrase repo on GitHub