diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index d1b43ce08e407f..aeb696936530be 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -485,11 +485,14 @@ function tryFsResolve( ): string | undefined { const { file, postfix } = splitFileAndPostfix(fsPath) + // Dependencies like es5-ext use `#` in their paths. We don't support `#` in user + // source code so we only need to perform the check for dependencies. + const tryUnsplitted = fsPath.includes('#') && fsPath.includes('node_modules') + let res: string | undefined - // if there is a postfix, try resolving it as a complete path first (#4703) if ( - postfix && + tryUnsplitted && (res = tryResolveFile( fsPath, '', @@ -519,7 +522,7 @@ function tryFsResolve( for (const ext of options.extensions) { if ( - postfix && + tryUnsplitted && (res = tryResolveFile( fsPath + ext, '', @@ -554,7 +557,7 @@ function tryFsResolve( if (!tryIndex) return if ( - postfix && + tryUnsplitted && (res = tryResolveFile( fsPath, '',