From d27204ddfd7a87c6680b5562e364221b005a5343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9di-R=C3=A9mi=20Hashim?= <4295266+mediremi@users.noreply.github.com> Date: Thu, 6 Jan 2022 10:38:54 +0000 Subject: [PATCH] fix(create-module-loader): handle case where findProject root returns undefined (#151) --- lib/createModuleLoader.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/createModuleLoader.js b/lib/createModuleLoader.js index 68a1820..8514edf 100644 --- a/lib/createModuleLoader.js +++ b/lib/createModuleLoader.js @@ -14,7 +14,9 @@ module.exports = ({ parentModule, preferLocal = true }) => { // create a require fn bound to the cwd project's node_modules const root = findProjectRoot({ markers: ['package.json'] }) - const rootRequire = createRequire(path.resolve(root, 'package.json')) + const rootRequire = createRequire( + root ? path.resolve(root, 'package.json') : '/' + ) if (!preferLocal) { reporter.warn('Project-local module resolution for tools is disabled.')