Skip to content

module: clarify esm error message in require calls #57774

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const explainCommonJSGlobalLikeNotDefinedError = (e, url) => {
e.message += ' in ES module scope';

if (StringPrototypeStartsWith(e.message, 'require ')) {
e.message += ', you can use import instead';
e.message += ', use a static or dynamic import instead.';
}

const packageConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { pathToFileURL } = require('url');

assert.rejects(
import('data:text/javascript,require;'),
/require is not defined in ES module scope, you can use import instead$/
/require is not defined in ES module scope, use a static or dynamic import instead\.$/
).then(common.mustCall());
assert.rejects(
import('data:text/javascript,exports={};'),
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-typescript-eval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('expect fail eval TypeScript CommonJS syntax with input-type module-typescr
console.log(util.styleText('red', text));`]);

strictEqual(result.stdout, '');
match(result.stderr, /require is not defined in ES module scope, you can use import instead/);
match(result.stderr, /require is not defined in ES module scope, use a static or dynamic import instead\./);
strictEqual(result.code, 1);
});

Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-typescript-module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('expect failure of a .mts file with CommonJS syntax', async () => {
]);

strictEqual(result.stdout, '');
match(result.stderr, /require is not defined in ES module scope, you can use import instead/);
match(result.stderr, /require is not defined in ES module scope, use a static or dynamic import instead\./);
strictEqual(result.code, 1);
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-worker-eval-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ test('Worker eval commonjs typescript with --input-type=module-typescript', asyn
disableTypeScriptWarningFlag] });
const [err] = await once(w, 'error');
assert.strictEqual(err.name, 'ReferenceError');
assert.match(err.message, /require is not defined in ES module scope, you can use import instead/);
assert.match(err.message, /require is not defined in ES module scope, use a static or dynamic import instead\./);
});
Loading