diff options
author | 2023-08-17 19:34:05 -0700 | |
---|---|---|
committer | 2023-08-17 19:34:05 -0700 | |
commit | 0424fd8f6e7549ed779788006acdc97a8467e287 (patch) | |
tree | faec04e9f167eca0b72c6a19291f5bbae06068db /src/js/builtins/Module.ts | |
parent | cfbd1373e2cc8066493de74b551aeb53061e84a7 (diff) | |
download | bun-0424fd8f6e7549ed779788006acdc97a8467e287.tar.gz bun-0424fd8f6e7549ed779788006acdc97a8467e287.tar.zst bun-0424fd8f6e7549ed779788006acdc97a8467e287.zip |
Support Nitro (#4098)
* Add formatWithOptions
* tests and tweaks
* adjust
* changes
* hi
* add mark/measure stubs
* stuff
* allow unix absolute paths here
* typo
* rebase
* fix stats
Diffstat (limited to 'src/js/builtins/Module.ts')
-rw-r--r-- | src/js/builtins/Module.ts | 12 |
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) { |