From de4061c7063323b8a398e1a4705e09e8733d89da Mon Sep 17 00:00:00 2001 From: Dylan Li Date: Fri, 28 Jul 2023 17:41:57 +0800 Subject: [PATCH] require from patchRequire can now read exports.require info from package.json --- src/patchRequire.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/patchRequire.js b/src/patchRequire.js index c3e31ebd..8b17155c 100644 --- a/src/patchRequire.js +++ b/src/patchRequire.js @@ -113,7 +113,8 @@ export default function patchRequire(vol, unixifyPaths = false, Module = require let pkg; try { - pkg = packageMainCache[requestPath] = JSON.parse(json).main; + const pkgJson = JSON.parse(json); + pkg = packageMainCache[requestPath] = pkgJson.exports && pkgJson.exports.require || pkgJson.main; } catch (e) { e.path = jsonPath; e.message = 'Error parsing ' + jsonPath + ': ' + e.message;