[vite] Internal server error: Failed to resolve import "./chunk-J5JSNRMJ.js" Does the file exist?
See original GitHub issueDescribe the bug
[env] vite: 2.6.14 node: 12.18 vue: 3.2.21 vue-router: 4.0.12
file: node_modules/.vite/vue-router.js?v=a7f4b19c
import { setupDevtoolPlugin } from './chunk-J5JSNRMJ.js'
dev 模式下,在删除 .vite 目录后,冷启动时出现。 多次测试发现有 50% 几率出现这个错误 报错后系统会提示 [vite]: dependencies updated, reloading page…随即页面刷新后恢复正常。
在报错之前会有类似日志出现,表明中间有多次 updating 情况下才会触发问题
[vite] new dependencies found: axios, vue-router , updating...
[vite] Fail to load source Map for node_module/.vite/....chunk-xxx.js
[vite] new dependencies found: axios, vue-router , updating...
[vite] Fail to load source Map for node_module/.vite/....chunk-xxx.js
[vite] Internal server error: ....
Reproduction
- remove node_modules/.vite
- vite serve
- repeat the test
System Info
os: mac 10.15.7
shell: 5.7.1 --/bin/zsh
node: 12.18.3
yarn: 1.22.5
npm: 6.14.6
Used Package Manager
npm
Logs
No response
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 https://github.com/vuejs/vue-next 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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
[vite] Internal server error: Failed to resolve import "XXX" from ...
Does the file exist? Yes it exists! I checked.
Read more >Ask Question - Stack Overflow
Internal server error : Failed to resolve import "./store" from "src\main.ts". Does the file exist? The code is: import store from "./store";.
Read more >[vite] internal server error: failed to resolve import - You.com
下午11:07:21 [vite] Internal server error: Failed to resolve import "./banner.svg?component" from "src/pages/test/index.vue". Does the file exist?
Read more >Troubleshooting - Vite
As Vite does not bundle most of the files, browsers may request many files which ... For example, src/foo.js exists and src/bar.js contains:...
Read more >How to Set Up Path Resolving in Vite - Morioh
To my surprise, it did not work and I was welcome with this error: Failed to resolve import error. It turns out that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
总结 分析了源码后,大概了解到问题是与 vite 更新机制有关系! 如果要根本上解决这个问题,vite 需要改变它的更新机制,目前都是靠定时器进行处理,有重复刷新、编译等问题,很大可能是时序没控制好出现问题。
临时解决方法:提前把所有依赖库都添加到 optimizeDeps(或者external),这个报错问题就不会出现了。
解决原因分析 服务在第一次启动的时候会预编译所有库依赖。
潜在问题点分析
NEW_DEPENDENCY_BUILD_TIMEOUT = 1s
刷新页面,超时后返回 408 让客户端刷新页面debounceMs = 100ms
,执行rerun --> optimizeDeps
执行依赖更新上述两个定时器有交叉情况出现,相互影响,最终会导致随机出现之前描述的 internal Error 问题
还有一个不可忽视的问题是依赖库的问题 出现问题都是用到了 lodash-es、ant-design-vue 这类库,他们主要特点是依赖较多,预编译速度也会很慢,不排除每次请求编译过程中,超时等导致出现问题。
顺便说下,vite 场景我用到了 virtual module