浏览器报错: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 scripts per HTML spec.

场景还原:

在一个module模式下的js中引用另外一个export对象,就报错了,代码如下:

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 scripts per HTML spec.-QUI-Notes

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 scripts per HTML spec.-QUI-Notes

原因分析:

一般这种错误就是,引用文件是一个文件夹而不是一个引用文件。或者就是引用路径不对!!!

解决办法:

回到场景中,我们web.js开头的  import CSS from './css'   改成  import CSS from './css.js'   这样就可以解决这个异常问题。