From a941003730f7efa6e00b3ade1cc894f5d67ea54a Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 8 Feb 2022 15:48:46 +0100 Subject: [PATCH] fix: use `createRequire()` for `require.resolve()` (#986) --- src/runtimes/node/bundlers/zisi/resolve.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtimes/node/bundlers/zisi/resolve.ts b/src/runtimes/node/bundlers/zisi/resolve.ts index fc79cbd5b..0a425c15d 100644 --- a/src/runtimes/node/bundlers/zisi/resolve.ts +++ b/src/runtimes/node/bundlers/zisi/resolve.ts @@ -1,3 +1,4 @@ +import { createRequire } from 'module' import { version as nodeVersion } from 'process' import findUp from 'find-up' @@ -5,6 +6,8 @@ import pathExists from 'path-exists' import resolveLib from 'resolve' import semver from 'semver' +const requireLib = createRequire(__filename) + const BACKSLASH_REGEXP = /\\/g // Find the path to a module's `package.json` @@ -74,7 +77,7 @@ const resolvePathPreserveSymlinks = async function (path: string, baseDirs: stri } const resolvePathFollowSymlinks = function (path: string, baseDirs: string[]) { - return require.resolve(path, { paths: baseDirs }) + return requireLib.resolve(path, { paths: baseDirs }) } // `require.resolve()` on a module's specific file (like `package.json`)