The|The server responded with a non-JavaScript MIME type oftext/html
vue3+vite打包以后,项目切换路由触发(偶发触发)报:
After using vue-router, there is an error in packaging and running # Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Failed to fetch dynamically imported module.....
【The|The server responded with a non-JavaScript MIME type oftext/html】
文章图片
确实应该是vite2.xx的bug https://github.com/vitejs/vite/issues/863
注意: 在使用vue3+vite时候,只发现vue-router切换时触发此现象
问题:
// vue3+vite此种异步路由引入方法 开发调试时确实没有问题,但是vite打包以后就会触发报错
routes: [
{
path: "/",
name: "Home",
component: import(`../views/${view}.vue`)
}
]
解决方法:
// 这样引用虽然解决了问题(浏览器会提醒,不用管),但是在一些win10自带的低版本edge浏览器中还是会稀有触发
// 应该确实是vite的兼容性bug问题
import { defineAsyncComponent } from 'vue';
//异步组挂载器
routes: [
{
path: "/",
name: "Home",
component: defineAsyncComponent(() => import('../views/Home.vue'));
},
{
path: "/about",
name: "About",
component: defineAsyncComponent(() => import('../views/About.vue'));
}
]
后续持续跟进中...
推荐阅读
- win8系统如何安装SQL Server 2008管理工具【图文】
- SQLSERVERCROSS APPLY 与 OUTER APPLY 的应用
- 游戏|为什么像王者荣耀这样的游戏 Server 不愿意使用微服务()
- Appium新手入门—— Appium Server安装
- 在idea里面配置Application servers
- AndroidStudio3.0 注解报错Annotation processors must be explicitly declared now. The following dependenci
- Android开发中使用数据库时出现java.lang.IllegalStateException: Cannot perform this operation because the connect
- 在Workstation 14中导入vCenter Server Appliance 6.5
- .NETCore Sqlserver下对Dapper的扩展支持
- There is no Action mapped for namespace [/] and action name [m_hi] associated with context path [](代