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:
parent
2851a98072
commit
a938aaf36f
1 changed files with 9 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue