1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix(ext/node): better error for importing ES module via require() call (#15671)

This commit is contained in:
Bartek Iwańczuk 2022-08-29 19:48:27 +02:00 committed by GitHub
parent 2851a98072
commit a938aaf36f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -730,9 +730,15 @@
if (StringPrototypeEndsWith(filename, ".js")) {
const pkg = core.ops.op_require_read_package_scope(filename);
if (pkg && pkg.exists && pkg.typ == "module") {
throw new Error(
`Import ESM module: ${filename} from ${module.parent.filename}`,
);
let message = `Trying to import ESM module: ${filename}`;
if (module.parent) {
message += ` from ${module.parent.filename}`;
}
message += ` using require()`;
throw new Error(message);
}
}