Add a catch to support requiring installed modules

This commit is contained in:
Jonathan Clem
2021-04-21 16:58:37 -04:00
parent 3ca4cd5a00
commit c1c139b0ab
2 changed files with 40 additions and 4 deletions

View File

@@ -4,8 +4,14 @@ export const wrapRequire = new Proxy(__non_webpack_require__, {
apply: (target, thisArg, [moduleID]) => {
if (moduleID.startsWith('.')) {
moduleID = path.join(process.cwd(), moduleID)
return target.apply(thisArg, [moduleID])
}
try {
return target.apply(thisArg, [moduleID])
} catch (err) {
return target.resolve(moduleID, {paths: [...module.paths, process.cwd()]})
}
return target.apply(thisArg, [moduleID])
},
get: (target, prop, receiver) => {