From b6ec807e863e0e27cb16846f995c8e3a5c48b9fd Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Tue, 31 May 2022 20:13:01 +0900 Subject: [PATCH] fix: use createRequire(root) --- packages/vite/src/node/utils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 8d52dc2bfe1e53..b3d61c72e99bd4 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -795,12 +795,12 @@ export const requireResolveFromRootWithFallback = ( root: string, id: string ): string => { - // Search in the root directory first, and fallback to the default require paths. - const fallbackPaths = _require.resolve.paths?.(id) || [] - const path = _require.resolve(id, { - paths: [root, ...fallbackPaths] - }) - return path + // require in the root directory first, and fallback to the default require. + const _requireFromRoot = createRequire(path.resolve(root, './index.cjs')) + try { + return _requireFromRoot.resolve(id) + } catch {} + return _require.resolve(id) } // Based on node-graceful-fs