vite部署线上报MIME类型错误
· 阅读需 1 分钟
错误如下
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.
配置文件解决
注意: 添加头的方法在
amplify.yml可能有用, 但是主要是看你构建目录是否正确, 亚马逊配置如果目录不对, 有时候可以构建成功! Vite 默认构建目录是dist, CRA默认构建目录是build
使用“customHeaders”属性配置了所有 JavaScript 文件的 MIME 类型为“application/javascript”。

nginx解决
types {
application/javascript js;
}
还找到这个解决方法
sudo vi /etc/nginx/mime.types
找到或者补充这一行
application/javascript js
在末尾添加
application/javascript js mjs
重启nginx
sudo nginx -s reload
Apache 服务器解决
AddType application/javascript .js
