question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use native ESM for dev scripts

See original GitHub issue

Since we are now only building Babel on Node.js 14 (even if we still test it on Node.js 6), we can use native ECMAScript modules for the build scripts:

  • Top-level scripts There are a bunch of scripts/tests in the scripts folder: they can probably all be rewritten to ES modules. We can probably add "type": "module" to the top-level package.json, renaming config files (such as .eslintrc.js) to .cjs. Note that we cannot use ES modules for babel.config.js and jest.config.js, because those two files are used to run tests on Node.js 6.

  • babel-types/scripts can be rewritten to ES modules. These files should be renamed to .mjs, to keep the dist @babel/types files with the .js extension (they are CJS modules).

Please note that babel-types/scripts depends on the top-level scripts, so babel-types/scripts must be converted first (it cannot synchronously import an ESM file while still being CJS).

In order to test if your changes are still ok, running yarn (only when you clone the repo) and make build && yarn jest should be enough.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
JLHwungcommented, Oct 3, 2020

Note that we should also bump building requirements to ^12.16 || >= 14 in https://github.com/babel/babel/blob/main/CONTRIBUTING.md#developing

We can also update gulp to 4.2.0 which supports .mjs config.

1reaction
karansapoliacommented, Nov 2, 2020

@nicolo-ribaudo Yes, I was stuck on an error. Could use some help definitely. Let me create a draft PR so all can have a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ECMAScript modules (ESM) with Node.js
Learn about using ES modules in Node.js today and get a closer look at how you can migrate your codebase to make use...
Read more >
Native esm in a simple html+js use case - DEV Community ‍ ‍
In this series, I'll take a look on a simple usecase of js+html application, build with various js bundlers. For a start, let's...
Read more >
How to use ESM on the web and in Node.js - ByteofDev
The simplest way to use ESM on the web is by utilizing the native support for it. For about over 95% of users...
Read more >
TypeScript and native ESM on Node.js - 2ality
In this blog post, I'll explain everything you need to know in order to use and produce native ECMAScript modules on Node.js.
Read more >
Documentation - ECMAScript Modules in Node.js - TypeScript
Interoperating between the two module systems brings large challenges, with many new features to juggle; however, support for ESM in Node.js is now...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found