且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

拒绝执行脚本,因为它的MIME类型(...)和严格的MIME类型(...)

更新时间:2021-10-14 21:31:00

现在/app.bundle.js 返回

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /app.bundle.js</pre>
</body>
</html>

由于设置错误.

  • NG: app.use(express.static(__ dirname +'dist'));
  • 确定: app.use(express.static(__ dirname +'/dist'));

__ dirname 不包含斜杠.

  • 假设正确的路径是/.../myApp/dist/app.bundle.js
  • index.html 作为JavaScript文件来源 app.bundle.js ,MIME预计为 text/javascript 等.
  • 现在 app.use(express.static(__ dirname +'dist'))
  • ==> app.use(express.static('/.../myAppdist/app.bundle.js'))不存在.
  • express使用HTML返回404错误响应,其MIME是 text/html
  • To suppose the correct path is /.../myApp/dist/app.bundle.js
  • index.html sources app.bundle.js as javascript file, which MIME is expected to be text/javascript, etc.
  • now app.use(express.static(__dirname + 'dist'))
  • ==> app.use(express.static('/.../myAppdist/app.bundle.js')) does not exist.
  • express returns 404 error response with HTML, which MIME is text/html