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.

Is this an ESM-first module now?

See original GitHub issue

When bumping from 10.3.0 to 10.4.4 I encountered the following issue when building my project:

> Build error occurred
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/runner/work/monorepo/monorepo/website/node_modules/d3-array/src/index.js
require() of ES modules is not supported.
require() of /home/runner/work/monorepo/monorepo/website/node_modules/d3-array/src/index.js from /home/runner/work/monorepo/monorepo/website/node_modules/reaviz/dist/index.cjs.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/runner/work/monorepo/monorepo/website/node_modules/d3-array/package.json.

Is this an ESM-first module now?

In my opinion, this should be clearly stated in the documentation.

Also, since this breaks backward compatibility (given the current JS ecosystem), I think this should warrant a major version change; not a minor one.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jazznerd206commented, Nov 6, 2021

I don’t wanna get too far ahead of myself, but d3 might have solved the problem for us.

The specific dep that’s throwing the error for me is d3-array, and according to your package.json, you have v3.0.4, and there is a new version, 3.1.1 available as of 1 month ago. According to the changelog, they have updated it to es6, so import should actually work now.

I’ll report back after some testing.

2reactions
jazznerd206commented, Nov 4, 2021

@amcdnl

yeah buddy. i’ll give it a shot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Meet the Orion Service Module, the European-built brain of ...
The first service module is now integrated with the Orion vehicle for the first Artemis mission. The second service module is ready for ......
Read more >
ESM Loader with Node VM Module - Mauve's Blog
I've been wanting a browser-first / ESM-first environment for a while, and was excited when deno came out, but was disappointed that it...
Read more >
Publish ESM and CJS in a single package
A short tutorial of shipping both ESM and CJS dual formats in a single NPM package.
Read more >
Is it possible to use ES6 modules in Mocha tests?
Yes, as of Mocha version 9: Mocha is going ESM-first! This means that it will now use ESM import(test_file) to load the test...
Read more >
Dependency Pre-Bundling
Performance: Vite converts ESM dependencies with many internal modules into a ... By pre-bundling lodash-es into a single module, we now only need...
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