aboutsummaryrefslogtreecommitdiff
path: root/src/js/builtins/Module.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/builtins/Module.ts')
-rw-r--r--src/js/builtins/Module.ts12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/js/builtins/Module.ts b/src/js/builtins/Module.ts
index d6ebc8578..ca7c0fa91 100644
--- a/src/js/builtins/Module.ts
+++ b/src/js/builtins/Module.ts
@@ -82,7 +82,17 @@ export function require(this: CommonJSModuleRecord, id: string) {
}
export function requireResolve(this: string | { path: string }, id: string) {
- return $resolveSync(id, typeof this === "string" ? this : this?.path, false);
+ // This try catch is needed because err.code on ESM resolves is ERR_MODULE_NOT_FOUND
+ // while in require.resolve this error code is only MODULE_NOT_FOUND.
+ // `local-pkg` will check for .code's exact value, and log extra messages if we don't match it.
+ try {
+ return $resolveSync(id, typeof this === "string" ? this : this?.path, false);
+ } catch (error) {
+ var e = new Error(`Cannot find module '${id}'`);
+ e.code = "MODULE_NOT_FOUND";
+ // e.requireStack = []; // TODO: we might have to implement this
+ throw e;
+ }
}
export function requireNativeModule(id: string) {