Skip to content

Commit

Permalink
esm: clarify ERR_REQUIRE_ESM errors
Browse files Browse the repository at this point in the history
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: nodejs/node#39175
PR-URL: nodejs/node#49521
Backport-PR-URL: nodejs/node#50669
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]>
  • Loading branch information
sercher committed Apr 25, 2024
1 parent 6ddeff5 commit 53e302e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion graal-nodejs/lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ E('ERR_REQUIRE_ESM',
msg += `\n${basename} is treated as an ES module file as it is a .js ` +
'file whose nearest parent package.json contains "type": "module" ' +
'which declares all .js files in that package scope as ES modules.' +
`\nInstead rename ${basename} to end in .cjs, change the requiring ` +
`\nInstead either rename ${basename} to end in .cjs, change the requiring ` +
'code to use dynamic import() which is available in all CommonJS ' +
'modules, or change "type": "module" to "type": "commonjs" in ' +
`${packageJsonPath} to treat all .js files as CommonJS (using .mjs for ` +
Expand Down
2 changes: 1 addition & 1 deletion graal-nodejs/test/es-module/test-cjs-esm-warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('CJS ↔︎ ESM interop warnings', { concurrency: true }, () => {
);
assert.ok(
stderr.replaceAll('\r', '').includes(
`Instead rename ${basename} to end in .cjs, change the requiring ` +
`Instead either rename ${basename} to end in .cjs, change the requiring ` +
'code to use dynamic import() which is available in all CommonJS ' +
`modules, or change "type": "module" to "type": "commonjs" in ${pjson} to ` +
'treat all .js files as CommonJS (using .mjs for all ES modules ' +
Expand Down

0 comments on commit 53e302e

Please sign in to comment.