mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(ext/node): better error for importing ES module via require() call (#15671)
This commit is contained in:
parent
2851a98072
commit
a938aaf36f
1 changed files with 9 additions and 3 deletions
|
@ -730,9 +730,15 @@
|
||||||
if (StringPrototypeEndsWith(filename, ".js")) {
|
if (StringPrototypeEndsWith(filename, ".js")) {
|
||||||
const pkg = core.ops.op_require_read_package_scope(filename);
|
const pkg = core.ops.op_require_read_package_scope(filename);
|
||||||
if (pkg && pkg.exists && pkg.typ == "module") {
|
if (pkg && pkg.exists && pkg.typ == "module") {
|
||||||
throw new Error(
|
let message = `Trying to import ESM module: ${filename}`;
|
||||||
`Import ESM module: ${filename} from ${module.parent.filename}`,
|
|
||||||
);
|
if (module.parent) {
|
||||||
|
message += ` from ${module.parent.filename}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
message += ` using require()`;
|
||||||
|
|
||||||
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue