Skip to content

Commit ebd7153

Browse files
committed
esm: clarify ERR_REQUIRE_ESM errors
In nodejs#39175, better ESM errors were introduced. This commit tweaks the language in the error slightly to make it clear that there are three different options to resolve the error. Refs: nodejs#39175
1 parent 5402185 commit ebd7153

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/internal/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ E('ERR_REQUIRE_ESM',
15481548
msg += `\n${basename} is treated as an ES module file as it is a .js ` +
15491549
'file whose nearest parent package.json contains "type": "module" ' +
15501550
'which declares all .js files in that package scope as ES modules.' +
1551-
`\nInstead rename ${basename} to end in .cjs, change the requiring ` +
1551+
`\nInstead either rename ${basename} to end in .cjs, change the requiring ` +
15521552
'code to use dynamic import() which is available in all CommonJS ' +
15531553
'modules, or change "type": "module" to "type": "commonjs" in ' +
15541554
`${packageJsonPath} to treat all .js files as CommonJS (using .mjs for ` +

test/es-module/test-cjs-esm-warn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('CJS ↔︎ ESM interop warnings', { concurrency: true }, () => {
3131
);
3232
assert.ok(
3333
stderr.replaceAll('\r', '').includes(
34-
`Instead rename ${basename} to end in .cjs, change the requiring ` +
34+
`Instead either rename ${basename} to end in .cjs, change the requiring ` +
3535
'code to use dynamic import() which is available in all CommonJS ' +
3636
`modules, or change "type": "module" to "type": "commonjs" in ${pjson} to ` +
3737
'treat all .js files as CommonJS (using .mjs for all ES modules ' +

0 commit comments

Comments
 (0)