-
Notifications
You must be signed in to change notification settings - Fork 10
replace commmonjs2 to module for export #88
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,23 @@ module.exports = { | |
| entry: { | ||
| index: './src/index.ts', | ||
| }, | ||
| experiments: { | ||
| ...( defaultConfig.experiments || {} ), | ||
| outputModule: true, | ||
| }, | ||
| output: { | ||
| ...defaultConfig.output, | ||
| path: path.resolve( __dirname, 'dist' ), | ||
| filename: '[name].js', | ||
| filename: '[name].mjs', | ||
| library: { | ||
| type: 'commonjs2', | ||
| type: 'module', | ||
| }, | ||
| module: true, | ||
| chunkFormat: 'module', | ||
|
Comment on lines
7
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Single Webpack is configured with a single entry ( Either add corresponding entries here (and update the subpath exports to 🛠️ Example: multi-entry output entry: {
index: './src/index.ts',
+ 'components/ui/index': './src/components/ui/index.ts',
+ 'providers/index': './src/providers/index.ts',
+ 'themes/index': './src/themes/index.ts',
+ 'utils/index': './src/utils/index.ts',
+ 'components/settings/index': './src/components/settings/index.ts',
},Based on learnings: "Use sub-path exports for organized imports: wedevs/plugin-ui/settings, wedevs/plugin-ui/components/ui, wedevs/plugin-ui/providers, wedevs/plugin-ui/themes, wedevs/plugin-ui/utils". 🤖 Prompt for AI Agents |
||
| environment: { | ||
| ...( defaultConfig.output?.environment || {} ), | ||
| module: true, | ||
| dynamicImport: true, | ||
| }, | ||
| clean: true, | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Is require(esm) stable by default on Node.js 22.12 and what is the behavior on Node 22.0-22.11 when require() targets a .mjs file?💡 Result:
No, require(esm) is not stable by default on Node.js 22.12. It is enabled by default (unflagged) but remains experimental, emitting an experimental warning on first use (unless from node_modules). It became fully stable later, as noted in end-of-2025 sources. On Node.js 22.0-22.11, require targeting a .mjs file throws ERR_REQUIRE_ESM by default. The feature requires the --experimental-require-module flag to load synchronous ESM (no top-level await), returning a namespace object similar to dynamic import. Without the flag, .mjs files cannot be required from CommonJS.
Citations:
"require": "./dist/index.mjs"is a semantic mismatch and breaks on Node 22.0–22.11..mjsfiles are always parsed as ES modules by Node.js, so pointing therequirecondition at an.mjsis incorrect. On Node 22.0–22.11 (within your declaredengines.node: ">=22"range), this will throwERR_REQUIRE_ESMfor any CommonJS consumer. Even on Node 22.12 and later,require(esm)remains experimental (enabled-by-default but with warnings), not a stable feature.Pick one of the following:
ESM-only package (recommended, matches the webpack output): drop the
requirecondition and declare the package as ESM.📦 Proposed change — ESM-only
Dual-format: emit a separate CJS bundle from webpack and repoint
requireat it (e.g.dist/index.cjs).📝 Committable suggestion
🤖 Prompt for AI Agents