Skip to content

Commit

Permalink
fix: handle windows relative path handling
Browse files Browse the repository at this point in the history
On Windows, when a folder is on a virtual drive (e.g. `subst X: C:/dev`),
then symlink resolving will end up causing the root of the project
and the imported files to be on separate drives.

This leads into a situations where `path.relative(root, entryFile)` does
not return a relative path.

Updates vitejs#4635
  • Loading branch information
egonelbre committed Nov 3, 2021
1 parent 7977e92 commit be2259a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export function esbuildDepPlugin(
if (
!relativePath.startsWith('./') &&
!relativePath.startsWith('../') &&
relativePath !== '.'
relativePath !== '.' &&
// Windows: when root and entryFile are on different drives, then
// getting relative path is not possible.
!path.isAbsolute(relativePath)
) {
relativePath = `./${relativePath}`
}
Expand Down

0 comments on commit be2259a

Please sign in to comment.