diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts
index cf4c91e6bfc636..2c45771c46e101 100644
--- a/packages/vite/src/node/plugins/resolve.ts
+++ b/packages/vite/src/node/plugins/resolve.ts
@@ -874,15 +874,13 @@ export async function tryOptimizedResolve(
const metadata = depsOptimizer.metadata
- if (!importer) {
- // no importer. try our best to find an optimized dep
- const depInfo = optimizedDepInfoFromId(metadata, id)
- if (depInfo) {
- return depsOptimizer.getOptimizedDepId(depInfo)
- }
- return
+ const depInfo = optimizedDepInfoFromId(metadata, id)
+ if (depInfo) {
+ return depsOptimizer.getOptimizedDepId(depInfo)
}
+ if (!importer) return
+
// further check if id is imported by nested dependency
let resolvedSrc: string | undefined
diff --git a/playground/resolve-optimized-dup-deps/__tests__/resolve-optimized-dup-deps.spec.ts b/playground/resolve-optimized-dup-deps/__tests__/resolve-optimized-dup-deps.spec.ts
deleted file mode 100644
index e2c1507ecdb2ff..00000000000000
--- a/playground/resolve-optimized-dup-deps/__tests__/resolve-optimized-dup-deps.spec.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { expect, test } from 'vitest'
-import { page } from '~utils'
-
-test('resolve-optimized-dup-deps', async () => {
- expect(await page.textContent('.a')).toBe('test-package-a:test-package-b-v2')
- expect(await page.textContent('.b')).toBe('test-package-b-v1')
-})
diff --git a/playground/resolve-optimized-dup-deps/index.html b/playground/resolve-optimized-dup-deps/index.html
deleted file mode 100644
index 89b7bca36300e7..00000000000000
--- a/playground/resolve-optimized-dup-deps/index.html
+++ /dev/null
@@ -1,17 +0,0 @@
-
direct dependency A
-
-
-direct dependency B
-
-
-
diff --git a/playground/resolve-optimized-dup-deps/package-a/index.js b/playground/resolve-optimized-dup-deps/package-a/index.js
deleted file mode 100644
index 52c82187d5ee47..00000000000000
--- a/playground/resolve-optimized-dup-deps/package-a/index.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import b from '@vitejs/test-resolve-optimized-dup-deps-package-b'
-
-// should get test-package-a:test-package-b-v2
-const result = 'test-package-a:' + b
-
-export default result
diff --git a/playground/resolve-optimized-dup-deps/package-a/package.json b/playground/resolve-optimized-dup-deps/package-a/package.json
deleted file mode 100644
index a2c0067d1573cb..00000000000000
--- a/playground/resolve-optimized-dup-deps/package-a/package.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "name": "@vitejs/test-resolve-optimized-dup-deps-package-a",
- "private": true,
- "version": "1.0.0",
- "main": "index.js",
- "dependencies": {
- "@vitejs/test-resolve-optimized-dup-deps-package-b": "file:../package-b-v2"
- }
-}
diff --git a/playground/resolve-optimized-dup-deps/package-b-v1/index.js b/playground/resolve-optimized-dup-deps/package-b-v1/index.js
deleted file mode 100644
index 7d6c1ef0a992f1..00000000000000
--- a/playground/resolve-optimized-dup-deps/package-b-v1/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-// test-package-b-v1 is install and imported by user
-// it is written in cjs and should be optimized
-module.exports = 'test-package-b-v1'
diff --git a/playground/resolve-optimized-dup-deps/package-b-v1/package.json b/playground/resolve-optimized-dup-deps/package-b-v1/package.json
deleted file mode 100644
index 68b1c74f57f8e0..00000000000000
--- a/playground/resolve-optimized-dup-deps/package-b-v1/package.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "name": "@vitejs/test-resolve-optimized-dup-deps-package-b",
- "private": true,
- "version": "1.0.0",
- "main": "index.js"
-}
diff --git a/playground/resolve-optimized-dup-deps/package-b-v2/index.js b/playground/resolve-optimized-dup-deps/package-b-v2/index.js
deleted file mode 100644
index 204404e745db09..00000000000000
--- a/playground/resolve-optimized-dup-deps/package-b-v2/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-// test-package-b-v2 is install and imported by test-package-a
-// it is written in esm. it is not optimized
-export default 'test-package-b-v2'
diff --git a/playground/resolve-optimized-dup-deps/package-b-v2/package.json b/playground/resolve-optimized-dup-deps/package-b-v2/package.json
deleted file mode 100644
index ba9c84ea4538d6..00000000000000
--- a/playground/resolve-optimized-dup-deps/package-b-v2/package.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "name": "@vitejs/test-resolve-optimized-dup-deps-package-b",
- "private": true,
- "version": "2.0.0",
- "main": "index.js"
-}
diff --git a/playground/resolve-optimized-dup-deps/package.json b/playground/resolve-optimized-dup-deps/package.json
deleted file mode 100644
index 71267db3985ddd..00000000000000
--- a/playground/resolve-optimized-dup-deps/package.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "name": "@vitejs/test-resolve-optimized-dup-deps",
- "private": true,
- "version": "0.0.0",
- "scripts": {
- "dev": "vite",
- "build": "vite build",
- "debug": "node --inspect-brk ../../packages/vite/bin/vite",
- "preview": "vite preview"
- },
- "dependencies": {
- "@vitejs/test-resolve-optimized-dup-deps-package-a": "file:./package-a",
- "@vitejs/test-resolve-optimized-dup-deps-package-b": "file:./package-b-v1"
- }
-}
diff --git a/playground/resolve-optimized-dup-deps/vite.config.js b/playground/resolve-optimized-dup-deps/vite.config.js
deleted file mode 100644
index 2d6290f12b9098..00000000000000
--- a/playground/resolve-optimized-dup-deps/vite.config.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/**
- * @type {import('vite').UserConfig}
- */
-module.exports = {
- optimizeDeps: {
- exclude: ['@vitejs/test-resolve-optimized-dup-deps-package-a'],
- },
-}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7eaac2c8d05c04..37a5bb228ca779 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -829,26 +829,6 @@ importers:
playground/resolve-linked:
specifiers: {}
- playground/resolve-optimized-dup-deps:
- specifiers:
- '@vitejs/test-resolve-optimized-dup-deps-package-a': file:./package-a
- '@vitejs/test-resolve-optimized-dup-deps-package-b': file:./package-b-v1
- dependencies:
- '@vitejs/test-resolve-optimized-dup-deps-package-a': file:playground/resolve-optimized-dup-deps/package-a
- '@vitejs/test-resolve-optimized-dup-deps-package-b': file:playground/resolve-optimized-dup-deps/package-b-v1
-
- playground/resolve-optimized-dup-deps/package-a:
- specifiers:
- '@vitejs/test-resolve-optimized-dup-deps-package-b': file:../package-b-v2
- dependencies:
- '@vitejs/test-resolve-optimized-dup-deps-package-b': file:playground/resolve-optimized-dup-deps/package-b-v2
-
- playground/resolve-optimized-dup-deps/package-b-v1:
- specifiers: {}
-
- playground/resolve-optimized-dup-deps/package-b-v2:
- specifiers: {}
-
playground/resolve/browser-field:
specifiers: {}
@@ -8726,26 +8706,6 @@ packages:
dep-a: file:playground/preload/dep-a
dev: true
- file:playground/resolve-optimized-dup-deps/package-a:
- resolution: {directory: playground/resolve-optimized-dup-deps/package-a, type: directory}
- name: '@vitejs/test-resolve-optimized-dup-deps-package-a'
- version: 1.0.0
- dependencies:
- '@vitejs/test-resolve-optimized-dup-deps-package-b': file:playground/resolve-optimized-dup-deps/package-b-v2
- dev: false
-
- file:playground/resolve-optimized-dup-deps/package-b-v1:
- resolution: {directory: playground/resolve-optimized-dup-deps/package-b-v1, type: directory}
- name: '@vitejs/test-resolve-optimized-dup-deps-package-b'
- version: 1.0.0
- dev: false
-
- file:playground/resolve-optimized-dup-deps/package-b-v2:
- resolution: {directory: playground/resolve-optimized-dup-deps/package-b-v2, type: directory}
- name: '@vitejs/test-resolve-optimized-dup-deps-package-b'
- version: 2.0.0
- dev: false
-
file:playground/ssr-deps/css-lib:
resolution: {directory: playground/ssr-deps/css-lib, type: directory}
name: '@vitejs/test-css-lib'