Skip to content

Commit 3a9ea09

Browse files
danielcomptonruyadorno
authored andcommitted
esm: clarify ERR_REQUIRE_ESM errors
In #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: #39175 PR-URL: #49521 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
1 parent 6e56f2d commit 3a9ea09

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
@@ -1542,7 +1542,7 @@ E('ERR_REQUIRE_ESM',
15421542
msg+=`\n${basename} is treated as an ES module file as it is a .js `+
15431543
'file whose nearest parent package.json contains "type": "module" '+
15441544
'which declares all .js files in that package scope as ES modules.'+
1545-
`\nInstead rename ${basename} to end in .cjs, change the requiring `+
1545+
`\nInstead either rename ${basename} to end in .cjs, change the requiring `+
15461546
'code to use dynamic import() which is available in all CommonJS '+
15471547
'modules, or change "type": "module" to "type": "commonjs" in '+
15481548
`${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)