前端项目部署服务器后,使用浏览器访问报错如下:
Failed to load module script: Expected a JavaScript-or-Wasm 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.
这时可能会认为是nginx配置的问题。是,也不是。
这个错误的真正原因是服务器上缺少了index.html引用的第一个js文件报的错。
那为什么不报404,而是这么一个奇怪的问题呢?
nginx的配置:
server {
listen 80;
server_name test.test.cn;
client_max_body_size 10m;
location / {
proxy_set_header Host $http_host;
root /data/html/ysh;
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
上面是大多数前端项目在nginx里的标准配置。
因为浏览器访问的是js文件,而这个文件不在,就因为上面的配置的会返回index.html的内容,这样就造成了浏览识别js文件而不正确,认为返回了"text/html"报了上面的错误。
找了一圈解决上面问题的nginx的配置,配置了又配置,最终是因为服务器上少了文件,你说气不气。
3493

被折叠的 条评论
为什么被折叠?



