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.

[Enhancement]: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

See original GitHub issue

system: macOS node version: 14.2 webpack@4.43.0 webpack-cli@3.3.11

So, i have config file “webpack.config.js” export default { entry: './i.js', output: { filename: 'bundle.js' } }

in package.json i have “type”: “module”

in i.js i have code

import * as path from 'path';
console.log(path);

so i use cmd webpack --config webpack.config.js

and got error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/x8core/Projects/anyx-cli/webpack.config.js
require() of ES modules is not supported.

In documentation i see. “When using webpack to bundle your application, you can pick from a variety of module syntax styles including ES6”

Why i am getting such error? Am i need to use babel?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:18
  • Comments:28 (9 by maintainers)

github_iconTop GitHub Comments

121reactions
naliferovcommented, Sep 9, 2020

This is absolutely madness

23reactions
alexander-akaitcommented, Nov 6, 2020

Because you can’t use import inside cjs, please read how it works

Read more comments on GitHub >

github_iconTop Results From Across the Web

Must use import to load ES Module - javascript - Stack Overflow
json file I still am getting an error. Trying to decipher the error, I wonder if the problem is that svg2img is not...
Read more >
Error [ERR_REQUIRE_ESM]: Must use import to load ES ...
It seems indeed an issue with that module. I have created the node.js program from the readme: bash-5.0$ cat /data/test.js var md =...
Read more >
Must use import to load ES Module - Netlify Support Forums
Hello, I have been getting this error on production, but it works fine in my ... Error [ERR_REQUIRE_ESM]: Must use import to load...
Read more >
ECMAScript modules | Node.js v19.3.0 Documentation
startup/index.js' ) must also be fully specified. This behavior matches how import ... Instead, use import() to load an ES module from a...
Read more >
ostiahailo - Sonar Community - SonarSource
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ... ERROR: internal/modules/cjs/loader.js:1174 ERROR: throw new ...
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