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.

Babel runtime dependency will crash node (esm modules)

See original GitHub issue

Issue

Running tests without any transpilation with nodejs will lead to issues with react-flow v9+. This wasn’t the case before.

Reproduce

Repository with steps how to reproduce this issue: https://github.com/andys8/react-flow-node-issue-example

Error

internal/modules/cjs/loader.js:1092
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/user/dev/repository/react-flow-node-issue-example/node_modules/@babel/runtime/helpers/esm/extends.js
require() of ES modules is not supported.
require() of /home/user/dev/repository/react-flow-node-issue-example/node_modules/@babel/runtime/helpers/esm/extends.js from /home/user/dev/repository/react-flow-node-issue-example/node_modules/react-flow-renderer/dist/ReactFlow.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 extends.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/user/dev/repository/react-flow-node-issue-example/node_modules/@babel/runtime/helpers/esm/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:13)
    at Module.load (internal/modules/cjs/loader.js:940:32)
    at Function.Module._load (internal/modules/cjs/loader.js:781:14)
    at Module.require (internal/modules/cjs/loader.js:964:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/user/dev/repository/react-flow-node-issue-example/node_modules/react-flow-renderer/dist/ReactFlow.js:6:1)
    at Module._compile (internal/modules/cjs/loader.js:1075:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1096:10)
    at Module.load (internal/modules/cjs/loader.js:940:32)
    at Function.Module._load (internal/modules/cjs/loader.js:781:14) {
  code: 'ERR_REQUIRE_ESM'
}
npm ERR! Test failed.  See above for more details.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
moklickcommented, Feb 25, 2021

This is really strange. We haven’t change the babel plugins or the rollup config. The problem is that these packages are required by the current production build:

require('@babel/runtime/helpers/esm/extends');
require('@babel/runtime/helpers/esm/objectWithoutPropertiesLoose');

In v8.8.0 the weren’t. Maybe there is a new option for one of the babel or rollup plugins. I will try to fix it.

Note: This issue occurs since we are importing react-redux.

1reaction
andys8commented, Feb 26, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Babel error: Unknown option: .config when trying to upgrade ...
Now I am trying to upgrade dependencies to the latest versions and replace deprecated dependencies. When trying to build my app.
Read more >
babel-loader - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
@babel/runtime-corejs2 | Yarn - Package Manager
babel's modular runtime helpers with core-js@2 polyfilling. readme. babel. The compiler for writing next generation JavaScript. Gitpod ready-to-code. v7 npm ...
Read more >
JavaScript modules - MDN Web Docs
Use of native JavaScript modules is dependent on the import and ... as a module by runtimes such as Node.js, and build tools...
Read more >
API - esbuild
It can also be used to import code in node at run time from a package that cannot be ... echo 'module.exports =...
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