From c21d0cca09b7a39ed076dcca51f3eb1173805227 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 5 Oct 2025 16:01:14 -0500 Subject: [PATCH] Fix resolving deep version conflicts --- src/lib/build/esmPlugin.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/lib/build/esmPlugin.ts b/src/lib/build/esmPlugin.ts index ce5c61cc..53a2bf8f 100644 --- a/src/lib/build/esmPlugin.ts +++ b/src/lib/build/esmPlugin.ts @@ -133,14 +133,23 @@ export function esmPlugin(packageLock: PackageLock, target?: string): Plugin { const root = `node_modules/${name}`; return has(root) ? root : undefined; } + + // First, check for nested node_modules directly inside the importer's package + const nested = `${base}/node_modules/${name}`; + if (has(nested)) return nested; + + // Then walk up the tree looking for hoisted versions let current: string | undefined = base; while (current && current.length) { - const candidate = `${current}/node_modules/${name}`; - if (has(candidate)) return candidate; - const next = current.replace(/\/node_modules\/[^/]+$/, ""); + // Remove the last package from the path (handling scoped packages like @scope/name) + const next = current.replace(/\/node_modules\/(@[^/]+\/)?[^/]+$/, ""); if (next === current) break; current = next; + const candidate = `${current}/node_modules/${name}`; + if (has(candidate)) return candidate; } + + // Finally check root const root = `node_modules/${name}`; return has(root) ? root : undefined; };