Skip to content

Commit 20ce748

Browse files
authored
Allow requiring Node builtins.
This should fix #16, allowing Node builtin modules to be required when using a JS entry module.
1 parent 5d827f8 commit 20ce748

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ async function prerender (parentCompilation, request, options, inject, loader) {
216216
window.require = moduleId => {
217217
const asset = compilation.assets[moduleId.replace(/^\.?\//g, '')];
218218
if (!asset) {
219-
throw Error(`Error: Module not found. attempted require("${moduleId}")`);
219+
try {
220+
return require(moduleId);
221+
} catch (e) {
222+
throw Error(`Error: Module not found. attempted require("${moduleId}")`);
223+
}
220224
}
221225
const mod = { exports: {} };
222226
window.eval(`(function(exports, module, require){\n${asset.source()}\n})`)(mod.exports, mod, window.require);

0 commit comments

Comments
 (0)