diff --git a/packages/vite/src/node/fsUtils.ts b/packages/vite/src/node/fsUtils.ts index ae1892e989677c..9536218c8f8ce4 100644 --- a/packages/vite/src/node/fsUtils.ts +++ b/packages/vite/src/node/fsUtils.ts @@ -189,6 +189,10 @@ export function createCachedFsUtils(config: ResolvedConfig): FsUtils { function getDirentCacheFromPath( normalizedFile: string, ): DirentCache | false | undefined { + // path.posix.normalize may return a path either with / or without / + if (normalizedFile[normalizedFile.length - 1] === '/') { + normalizedFile = normalizedFile.slice(0, -1) + } if (normalizedFile === root) { return rootCache } diff --git a/playground/resolve/__tests__/resolve.spec.ts b/playground/resolve/__tests__/resolve.spec.ts index 45b87c23e4ab10..d930ac1e49a2df 100644 --- a/playground/resolve/__tests__/resolve.spec.ts +++ b/playground/resolve/__tests__/resolve.spec.ts @@ -215,6 +215,10 @@ test('Resolve doesnt interrupt page request with trailing query and .css', async expect(await page.textContent('h1')).toBe('Resolve') }) +test('resolve non-normalized absolute path', async () => { + expect(await page.textContent('.non-normalized')).toMatch('[success]') +}) + test.runIf(!isWindows)( 'Resolve doesnt interrupt page request that clashes with local project package.json', async () => { diff --git a/playground/resolve/index.html b/playground/resolve/index.html index 89eced2e7149e9..fa6b5afbb84cd6 100644 --- a/playground/resolve/index.html +++ b/playground/resolve/index.html @@ -167,6 +167,9 @@

resolve.conditions

resolve package that contains # in path

+

resolve non normalized absolute path

+

+