diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 371609fdf23c83..97b032b2833e11 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -175,7 +175,10 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin { // as if they would have been imported through a bare import // Use the original id to do the check as the resolved id may be the real // file path after symlinks resolution - const isNodeModule = !!normalizePath(id).match(nodeModulesInPathRE) + const isNodeModule = + nodeModulesInPathRE.test(normalizePath(id)) || + nodeModulesInPathRE.test(normalizePath(resolved)) + if (isNodeModule && !resolved.match(DEP_VERSION_RE)) { const versionHash = depsOptimizer.metadata.browserHash if (versionHash && OPTIMIZABLE_ENTRY_RE.test(resolved)) {