Paul Krill
Editor at Large

Sucrase rivals Babel JavaScript compiler for development use

news
Jun 27, 20192 mins

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

10 hottest IT jobs primary
Credit: 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

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author