前端服务器部署报错记录
报错1:Refused to apply style from 'http://xxxxxxx.online/assets/index.DepkYCYv.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled. index-Dnq3oQAv.js:1
解释:浏览器期望加载的 CSS 文件(index.DepkYCYv.css
)的 MIME 类型为 text/css
,但服务器返回的是 text/plain
。这导致浏览器拒绝应用样式
报错2:Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/plain". Strict MIME type checking is enforced for module scripts per HTML spec.
解释:浏览器尝试加载的 JavaScript 模块(index-Dnq3oQAv.js
)期望的 MIME 类型为 application/javascript
或 text/javascript
,但服务器返回了 text/plain
。由于严格 MIME 类型检查(Strict MIME type checking
)已启用,浏览器拒绝执行该脚本
1.修改nginx.conf
解释:此配置将 .js
文件的 MIME 类型明确指定为 application/javascript
,确保浏览器能正确识别 JavaScript 文件类型
增加配置
types {application/javascript js;}
2.修改nginx.conf 增加last
解释:在 Nginx 配置中,last
的主要作用是 停止当前请求的后续处理,并根据重写后的 URI 重新发起一个新的请求,新请求会从第一阶段(如 server
块)开始重新匹配所有规则
3.修改路由为hash模式