Start Using Babel 7 Beta Today!

Jeff Dolle Blocked Unblock Follow Following Nov 13, 2017

Babel 7 is in beta right now (v7.0.0-beta.32), but with so many great features, some of us just couldn’t wait.

TLDR; New features!!!… To install, replace babel packages with @babel/* version. Update babel config to match. Make a polyfill for @babel/register and call it before running tests. For Jest, temporarily use babel-7-jest.

New Features

Before getting into the setup process, let’s get hyped on some new features!

TypeScript Support! The #1 reason for hype. TypeScript is a fantastic tool and it’s great to see more support in the community. Note that to use the TypeScript preset, you will need to set --no-emit option to prevent tsc from outputting files. If writing any jsx, use as casting to prevent confusion between casts and jsx, and be sure to include the appropriate extensions for tools like Webpack, Jest, nyc, and @babel/register.

option to prevent tsc from outputting files. If writing any jsx, use casting to prevent confusion between casts and jsx, and be sure to include the appropriate extensions for tools like Webpack, Jest, nyc, and @babel/register. Optional Chaining. The best feature of Coffeescript is now available through Babel! Unfortunately, TypeScript does not yet support this feature, but it’s been in talks for a while.

Optional Catch Binding. A minor detail, but this enables catch blocks without defining a catch parameter.

Numeric Separators. Make numeric literals more readable by creating a visual separation (a _ ) between groups of digits

) between groups of digits Allow configuring babel using babelrc.js (#4630). This is to counteract the deprecation of env in .babelrc. Which was a decision based on confusion around the @babel/preset-env package and setting the env option.

in .babelrc. Which was a decision based on confusion around the package and setting the option. Scoped Packages. Not really part of Babel’s feature set, but all Babel packages have been moved in to Babel’s scope and must now be installed as npm install @babel/preset-react rather than npm install babel-preset-react@next . This is a slight but important adjustment. Moving packages under the babel scope frees conflicts with other packages and makes babel packages unambiguous, making it clear to new developers which packages are official.

Installing Babel 7 Beta

For an existing project, first uninstall all existing babel packages. Next, install the new scoped packages. You should now have nothing prefixed with “babel” in package.json unless you use babel-loader, which then needs upgraded to 8.0.0-beta.0.

With the packages updated, adjust the package.json, .babelrc, or .babelrc.js. A configuration that uses the new @babel/preset-typescript might look like: