From 20ce74865841eca65fa1948735afff956d99abf7 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 22 Feb 2019 09:01:27 -0500 Subject: [PATCH] Allow requiring Node builtins. This should fix #16, allowing Node builtin modules to be required when using a JS entry module. --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 285c8ec..9a602e8 100644 --- a/src/index.js +++ b/src/index.js @@ -216,7 +216,11 @@ async function prerender (parentCompilation, request, options, inject, loader) { window.require = moduleId => { const asset = compilation.assets[moduleId.replace(/^\.?\//g, '')]; if (!asset) { - throw Error(`Error: Module not found. attempted require("${moduleId}")`); + try { + return require(moduleId); + } catch (e) { + throw Error(`Error: Module not found. attempted require("${moduleId}")`); + } } const mod = { exports: {} }; window.eval(`(function(exports, module, require){\n${asset.source()}\n})`)(mod.exports, mod, window.require);