Failed to load module script: Expected a JavaScript module script but the server responded with a MI

项目打包报错Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

使用vite build 打包后部署到生产后报这个错误

原因:
资源路径问题,请求的是 js 资源, 但是服务器找不到资源,默认返回 html 文件;但是服务器会对资源进行格式校验,然后报错

解决:
问题出在打包时候资源路径不对
配置vite.config.js
配置 base为 './'
重新打包部署即可

在这里插入图片描述
参考文章:Failed to load module script 解决方案

下班~

posted @ 2024-03-05 16:43  fruge365  阅读(72)  评论(0)    收藏  举报  来源