-
-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement]: Error [ERR_REQUIRE_ESM]: Must use import to load ES Module #1622
Comments
I already provide this information above: "in package.json i have "type": "module"" |
I solved this
by changing the extension of the
I tracked it down to the dynamic import: Here is the repo to reproduce this issue. Node -v: v14.4.0 |
When webpack config got
|
This error happens in webpack 4 because it uses require to include your
This uses the function webpack config model but just importing should work. In the future of webpack 5, webpack-cli 4, there should be native support for |
This is absolutely madness |
Unfortunately @rockerBOO's solution does not work for me, the following error occurs: #1274 |
@thSoft I have had success with using the
Note: Biggest to note is a lack of named exports in node modules. https://github.com/nodejs/node/blob/master/doc/api/esm.md |
So, it's been a while, but my Previous:
New:
Not exactly the same thing as supporting a |
just tried the rename and flag workaround and it doesn't work for me, i get it might be a version issue? i've got a mix here that i've carried over from older projects: "webpack": "^5.3.2",
"webpack-bundle-analyzer": "^3.9.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0" moving everything to latest, i get a repeat of an older issue: "webpack": "^5.4.0",
"webpack-bundle-analyzer": "^3.9.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0" webpack/webpack-dev-server#2029 but if i change my startup script from the old style to the new:
i end up back where i started: it's not clear where i should go from here. the older style is incompatible with wherever the config-yargs directory was yeeted off to. the newer style is incompatible with import/export statements? |
Because you can't use |
The manual, in case it helps: https://nodejs.org/docs/latest/api/esm.html |
@clshortfuse You suggestion isn't working with the latest Webpack (I think). This is my config: // webpack.config.cjs
module.exports = async function () {
return (await import("./webpack.config.mjs")).default;
}; // webpack.config.mjs
import path from "path";
export default {
entry: "./dist/main.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
}; All fine, the config looks good. Now when I run webpack I get an error:
looks like the latest webpack is running the config file through a custom VM, and not providing the needed ESM callback. EDIT: Looks like this issue was already described in #1274 and that was closed in favor of this issue. Why does Webpack run configs through a VM? Trying to prevent people from hacking on Webpack internals at runtime? |
Having the same issue. |
Solved on our side, but there is bug in |
If I understand correctly |
@snoack Unfortunately not, no API to disable it |
Would |
@snoack it work only before |
I know this isn't a solution for everyone, but my workaround was to change my I'm transforming it into ESM as a post-build hack. 🤷 👀 |
Found solution, some hacky, but works fine, but no v8 cache for config files, but v8 already cache ES modules, so nothing bad |
Using the latest webpack 4 and latest webpack 4 dev server (we cannot update to webpack 5 yet) I tried this workaround: module.exports = async (env, argv) => {
const config = await import('./webpack.config.mjs')
return config.default(env, argv)
} It ran me into the But then I get this error: So I "almost" came all the way, but got stuck there. Is there nothing I can do about it to make it work with Webpack 4 then? |
What is |
I was using these versions of all Webpack related packages: "webpack": "4.44.2",
"webpack-cli": "4.7.0",
"webpack-dev-server": "3.10.3",
"webpack-merge": "4.2.2" |
I see, put it in todo, we should fix compatibility with ES in near future, problem in |
I got this error with
|
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
so i use cmd
webpack --config webpack.config.js
and got error:
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?
The text was updated successfully, but these errors were encountered: