From 1b822d0598a6e13108da541e37d6e0ccb5c226f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Mussini?= Date: Tue, 6 Sep 2022 16:58:36 -0300 Subject: [PATCH] fix: ensure version query for relative node_modules imports (#10016) --- packages/vite/src/node/plugins/resolve.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)) {