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.

Try loading webpack config as ESM

See original GitHub issue

Is your feature request related to a problem? Please describe.

We are currently switching a few things to fully ESM with Node 16 (or trying it out at least) but got an error trying to use webpack config as full ESM.

[error] Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /webpack.config.mjs
    at new NodeError (node:internal/errors:329:5)
    at Module.load (node:internal/modules/cjs/loader:970:11)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at resolveCustomWebpackConfig (..@angular-builders/custom-webpack/dist/custom-webpack-builder.js:47:33)
    at Function.<anonymous> (..@angular-builders/custom-webpack/dist/custom-webpack-builder.js:26:46)
    at Generator.next (<anonymous>)
    at ..@angular-builders/custom-webpack/dist/custom-webpack-builder.js:8:71
    at new Promise (<anonymous>)

Describe the solution you’d like

Maybe check if its a ES module before loading it.

Describe alternatives you’ve considered

Let’s discuss

Additional context

https://github.com/webpack/webpack-cli/releases/tag/webpack-cli%404.5.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
just-jebcommented, Jan 25, 2022

Closing this in favor of #1101

1reaction
just-jebcommented, Jun 27, 2021

Ok, I’ll leave this issue open with a low priority in case someone has time to play around with it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESM import on webpackConfig - Stack Overflow
I'm building a webpack app and I'm interested in use ESM through the entire app, meaning that build the webpack.config file with ESM...
Read more >
How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >
ECMAScript Modules - webpack
ECMAScript Modules (ESM) is a specification for using Modules in the Web. It's supported by all modern browsers and the recommended way of...
Read more >
Lazy Loading | webpack
Let's try something different. We'll add an interaction to log some text to the console when the user clicks a button. However, we'll...
Read more >
Externals - webpack
config.js indicates that the module jquery in import $ from 'jquery' should be excluded from bundling. In order to replace this module ...
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