Guide · Open source
How to use Babel: compile modern JavaScript for older environments
Updated · written with AI from the project's own documentation and checked against our catalogue data
Babel is an open-source compiler that lets you write recent JavaScript and converts it into an older form that environments without support for those features can still run. This guide is for developers who want to understand what Babel does, where it fits in a build step, and whether it suits their project. By the end you will know how its input and output look, when it is worth using, and where to find detailed setup documentation.
Quick start
- 1Understand the transformation. Look at the README example that rewrites a nullish coalescing expression into an older equivalent. This shows what Babel produces.
- 2Try the REPL. Paste a snippet into the Babel REPL linked from babel.dev to see the output without installing anything.
- 3Check your prerequisites. Install Node.js. The README does not state a required version, so confirm it on babeljs.io.
- 4Install Babel as a package. Add Babel through your package manager, following the detailed setup guide at babeljs.io.
- 5Add a compile step. Wire Babel into your build pipeline so your source is compiled before it ships to your target environments.
- 6Read the detailed docs. Use babeljs.io for configuration and usage details, since the README excerpt points there rather than describing them.
What does Babel do?
Babel helps you write code in the latest version of JavaScript. When the environments your code runs in do not support certain features natively, Babel compiles those features down to a supported version.
The README shows an example. The newer nullish coalescing operator is rewritten as an equivalent older expression, so the same logic runs where the operator is not understood.
// In
function greet(input) {
return input ?? "Hello world";
}
// Out
function greet(input) {
return input != null ? input : "Hello world";
}Where does Babel fit in a web project?
Developers use Babel as a build step in web projects. That lets them use new language features without waiting for every browser to support them.
The README describes Babel as a command-line and build-tool library. It is not an app with a graphical interface.
- Write source code using recent JavaScript syntax.
- Run Babel as part of your build pipeline to produce output for your target environments.
- Ship the compiled output to the browsers or Node versions you support.
Try Babel before installing it
You can see the transformation without setting anything up. The README links to Babel's online REPL, where you can paste code and watch the output change.
- Open the REPL linked from the Babel README on babel.dev.
- Paste a snippet that uses a newer feature, such as nullish coalescing.
- Compare the input with the output to see how the syntax is rewritten.
Install Babel and its prerequisites
Babel is a JavaScript library, so you need Node.js installed. The README excerpt does not specify which Node.js version is required, so check the official Babel documentation at babeljs.io for current requirements.
The README excerpt gives a clone command for the repository. Cloning the source is useful if you want to read or contribute to Babel. Most projects instead install Babel as a package through their package manager and follow the setup guide on babeljs.io.
- Install Node.js.
- Get Babel through your package manager, following the detailed setup guide at babeljs.io.
- To work on the source itself, clone the repository.
git clone https://github.com/babel/babelCheck whether you need Babel at all
Babel only has work to do when your code uses features that some target environments do not support. If you only write for modern browsers, or for Node versions that already support every feature you use, there may be nothing to compile.
Babel is a good fit for web developers who need recent syntax while still supporting older browsers, teams with a build pipeline that can add a compile step, and library authors who need output that runs in a range of environments.
Where to get help and detailed docs
The README points to babeljs.io for detailed usage and documentation. For questions and support, the project suggests GitHub Discussions, its Slack community, Stack Overflow under the babeljs tag, or Bluesky. Bugs and feature requests go to the issue tracker, and CONTRIBUTING.md explains how to fill out the template.
What people use it for
- Using newer JavaScript syntax in a web app while still supporting older browsers.
- Producing library output that runs in a range of environments.
- Adding a compile step to a team build pipeline.
- Studying how JavaScript syntax transforms work by comparing input and output.
Frequently asked questions
Is Babel free to use?
Yes. Babel is released under the MIT licence, as stated in the README and the LICENSE file. The project is community-driven and maintained by volunteers.
What do I need to run Babel?
You need Node.js. The README excerpt does not give a version number, so check babeljs.io for the current requirement.
Do I need Babel if I only target modern browsers?
Possibly not. Babel compiles features that your target environments do not support. If those environments already support everything you use, there may be nothing to compile.
Where can I find the Babel documentation?
The README points to babeljs.io for detailed usage. The REPL linked from the README lets you test transformations in the browser.
Where can I get help if something breaks?
Use GitHub Discussions, the Babel Slack community, Stack Overflow with the babeljs tag, or Bluesky, as listed in the README. Report bugs through the issue template in the babel/babel repository.
How does Babel compare to SWC, esbuild or the TypeScript compiler?
The source lists SWC, esbuild and the TypeScript compiler as comparable projects but does not compare them in detail. Look at each project's documentation to judge speed, features and fit for your setup.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Babel suits web developers, teams with a build step, and library authors who need recent JavaScript syntax to run in older environments. If you only target modern browsers or Node versions that support your code, you may not need it, and comparable tools such as SWC, esbuild or the TypeScript compiler are worth evaluating.
Install options & downloads