-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Labels
Description
Describe the bug
When you mark a dependency as external via
resolve: {
external: ['test-utils'],
}
then provide the dependency via an import map
<script type="importmap">
{
"imports": {
"test-utils": "/test-utils.js"
}
}
</script>
The plugin still throws an error saying its unable to resolve the dependency.

Reproduction
https://github.com/swalker326/vite-import-map-testing
Steps to reproduce
pnpm i
pnpm dev
running the project in preview mode works fine though.
pnpm build
pnpm preview
System Info
System:
OS: macOS 15.6.1
CPU: (16) arm64 Apple M4 Max
Memory: 153.94 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.12.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.12.0/bin/npm
bun: 1.1.38 - ~/.bun/bin/bun
Watchman: 2025.06.30.00 - /opt/homebrew/bin/watchman
Browsers:
Brave Browser: 135.1.77.101
Chrome: 140.0.7339.82
Safari: 18.6
npmPackages:
@vitejs/plugin-react: ^5.0.0 => 5.0.2
vite: ^7.1.5 => 7.1.5
Used Package Manager
pnpm
Logs
VITE v7.1.5 ready in 560 ms
➜ Local: http://localhost:5176/
➜ Network: use --host to expose
➜ press h + enter to show help
1:01:17 PM [vite] (client) Pre-transform error: Failed to resolve import "test-utils" from "src/App.tsx". Does the file exist?
Plugin: vite:import-analysis
File: /Users/shanewalker/Developer/vite-import-map-testing/src/App.tsx:6:27
20 | import viteLogo from "/vite.svg";
21 | import "./App.css";
22 | import { greet, add } from "test-utils";
| ^
23 | function App() {
24 | _s();
1:01:17 PM [vite] Internal server error: Failed to resolve import "test-utils" from "src/App.tsx". Does the file exist?
Plugin: vite:import-analysis
File: /Users/shanewalker/Developer/vite-import-map-testing/src/App.tsx:6:27
20 | import viteLogo from "/vite.svg";
21 | import "./App.css";
22 | import { greet, add } from "test-utils";
| ^
23 | function App() {
24 | _s();
at TransformPluginContext._formatLog (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31527:43)
at TransformPluginContext.error (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31524:14)
at normalizeUrl (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:29996:18)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:30054:32
at async Promise.all (index 7)
at async TransformPluginContext.transform (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:30022:4)
at async EnvironmentPluginContainer.transform (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:31325:14)
at async loadAndTransform (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:26407:26)
at async viteTransformMiddleware (file:///Users/shanewalker/Developer/vite-import-map-testing/node_modules/.pnpm/vite@7.1.5/node_modules/vite/dist/node/chunks/dep-M_KD0XSK.js:27492:20)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
ryok90ryok90