Babel runtime dependency will crash node (esm modules)
See original GitHub issueIssue
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:
- Created 3 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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:
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.Awesome, the issue is fixed. Great work!
https://github.com/andys8/react-flow-node-issue-example/blob/master/README.md#update-issue-fixed