Skip to content

Commit

Permalink
fix: use createRequire(root)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed May 31, 2022
1 parent d449ace commit b6ec807
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/vite/src/node/utils.ts
Expand Up @@ -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
Expand Down

0 comments on commit b6ec807

Please sign in to comment.