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 script per HTML spec.
这发生在 Google Chrome 和任何支持 JavaScript 模块的现代浏览器中。例如,当“构建”Angular 8+ 应用程序时,通常会生成这个文件,它不是一个常规的 JavaScript 文件,而是一个 JavaScript 模块。
polyfills-es2015.js
X-Content-Type-Options
X-Content-Type-Options
HTTP 消息头相当于一个提示标志,被服务器用来提示客户端一定要遵循在 Content-Type
首部中对 MIME 类型 的设定,而不能对其进行修改。
nosniff
只应用于 "script
" 和 "style
" 两种类型.
解决方案:
在 Nginx 中,可以使用诸如服务器块中的配置来完成:
location ~ .js {
add_header Content-Type text/javascript;
}