ice
ice copied to clipboard
Vite 模式下通过 hash 打包,部署经常会报 Failed to fetch dynamically import module 错误
Vite 模式下通过 hash 打包,部署经常会报 Failed to fetch dynamically import module 错误
截图如下:

如何解决这种问题
- ice.js Version:2.6.3
- build.json Configuration:
{ "vite": true, "plugins": [ [ "build-plugin-ignore-style", { "libraryName": "antd" } ] ], "hash":true } - Node Version: v16.15.0
- Platform: windows 11
确认下地址是否存在,可以提供下复现的 demo
@ClarkXia 这个问题其实很常见,就是用户在前端用系统的时候,生产重新部署了一次,因为是用 hash 模式打包的,之前的文件已经被删除,用户不刷新浏览器的话点其他页面路由就会出现这样的问题,不知有没有什么解决方案?
hash 部署有两个特点:
- 去缓存
- 可回滚
开启主子 bundle 都会有对应的 hash 生成,如果是因为页面未刷新导致使用了上一版本资源造成的,这个是预期的表现,另外实践上肯定是建议不删除,这样也方便回滚 。