You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this refactor mean that we can write webpack.config.js in ESM without relying on the package.json "type": "module" because an ESM can easily import another ESM?
In addition to adopting the following settings, it’s also recommended not to set { "type": "module" } or use .mts files in bundler projects for now. Some bundlers adopt different ESM/CJS interop behavior under these circumstances, which TypeScript cannot currently analyze with "moduleResolution": "bundler". See issue #54102 for more information.
I want to know whether this issue can remove the need for "type": "module". The related issue of TypeScript#54102 is webpack/webpack#17288.
Notice that I didn't use @babel/register with config name webpack.config.babel.js and I didn't add "type": "module" in package.json. By webpack support with the consideration above, I should not add "type": "module" in package.json.
✔ ~/GitHub/Frontend % npm run dev development 20:41:36
> frontend@0.0.1 dev
> webpack server --mode development
[webpack-cli] Failed to load '/Users/ningwang/GitHub/Frontend/webpack.config.js' config
[webpack-cli] /Users/ningwang/GitHub/Frontend/webpack.config.js:1
import path from 'path'
^^^^^^
SyntaxError: Cannot use import statement outside a module
@alexander-akait OK, but I rarely see people using .mjs even in some popular projects, and as I have linked above, there are currently some bugs with the kindly added new option moduleResolution: bundler when type: module is set. So the common way(type: module) is buggy, and the rare way(.mjs) is ugly.
I thought that webpack-cli needs an explicit .mjs is because it's written in CJS. So this is not related and even this issue is completed we still have to use .mjs to use ESM syntax for our webpack configs?
It is not related to the fact that webpack-cli is written in the commonjs format. Yes, you need "type": "module" or mjs if you want to use ESM, anyway you also can use babel/etc to transpile ESM to commonjs and have the js extension
Hi! I'd like to contribute to this refactor.
Before I start working, could you please clarify the expected scope of this migration?
Should the entire webpack-cli package be migrated from CommonJS to ESM, or would you prefer a gradual module-by-module approach?
Are there any Node version compatibility constraints I should keep in mind (e.g., minimum supported Node version for enabling full ESM)?
Should "type": "module" be applied at the package level, or is the plan to use .mjs/.cjs for a hybrid approach?
Once I get confirmation on the direction you prefer, I can start by converting a small utility file and submit a draft PR so the approach can be reviewed early.
Activity
webpack-bot commentedon Apr 5, 2023
This issue had no activity for at least half a year.
It's subject to automatic issue closing if there is no activity in the next 15 days.
webpack-bot commentedon Apr 21, 2023
Issue was closed because of inactivity.
If you think this is still a valid issue, please file a new issue with additional information.
nyngwang commentedon Mar 7, 2024
Does this refactor mean that we can write
webpack.config.jsin ESM without relying on the package.json"type": "module"because an ESM can easily import another ESM?Background
There is currently some serious bug on TypeScript's new option
"moduleResolution": "bundler"when"type": "module"is set, and it's clearly stated on their documentation regarding working with bundler: https://www.typescriptlang.org/docs/handbook/modules/guides/choosing-compiler-options.html#im-using-a-bundler.I want to know whether this issue can remove the need for
"type": "module". The related issue of TypeScript#54102 is webpack/webpack#17288.alexander-akait commentedon Mar 7, 2024
You already can do it, we support commonjs and ESM formats
nyngwang commentedon Mar 7, 2024
@alexander-akait I can't. I got an error:
Notice that I didn't use
@babel/registerwith config namewebpack.config.babel.jsand I didn't add"type": "module"in package.json. By webpack support with the consideration above, I should not add"type": "module"in package.json.alexander-akait commentedon Mar 7, 2024
Rename
webpack.config.jstowebpack.config.mjs1 remaining item
alexander-akait commentedon Mar 7, 2024
You need to set
"type": "module"or havingmjs, it is not a webpack problem, it is how Node.js worksnyngwang commentedon Mar 7, 2024
@alexander-akait OK, but I rarely see people using
.mjseven in some popular projects, and as I have linked above, there are currently some bugs with the kindly added new optionmoduleResolution: bundlerwhentype: moduleis set. So the common way(type: module) is buggy, and the rare way(.mjs) is ugly.I thought that webpack-cli needs an explicit
.mjsis because it's written in CJS. So this is not related and even this issue is completed we still have to use.mjsto use ESM syntax for our webpack configs?alexander-akait commentedon Mar 7, 2024
It is not related to the fact that webpack-cli is written in the commonjs format. Yes, you need
"type": "module"ormjsif you want to use ESM, anyway you also can usebabel/etc to transpile ESM to commonjs and have thejsextensionmanzil-infinity180 commentedon Nov 16, 2024
@alexander-akait can i take this issue?
evenstensberg commentedon Jun 27, 2025
@manzil-infinity180 submit a pr :)
theEquinoxDev commentedon Dec 12, 2025
Hi! I'd like to contribute to this refactor.
Before I start working, could you please clarify the expected scope of this migration?
"type": "module"be applied at the package level, or is the plan to use.mjs/.cjsfor a hybrid approach?Once I get confirmation on the direction you prefer, I can start by converting a small utility file and submit a draft PR so the approach can be reviewed early.
Thanks!
alexander-akait commentedon Apr 7, 2026
Please don't touch this issue, it was planned for the next major release