[英]Getting "Failed to load module script..." even though I run my code on a local server
I get Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
我
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
after importing axios
into a javascript file.将
axios
导入 javascript 文件后。
Based on: ES6 modules in local files - The server responded with a non-JavaScript MIME type基于: 本地文件中的 ES6 模块 - 服务器以非 JavaScript MIME 类型响应
I though that all I had to do is to run my code on a server (eg http://127.0.0.1:8080/ ) instead of on the file system (eg file:///C:/Users/...
).我虽然我所要做的就是在服务器上运行我的代码(例如http://127.0.0.1:8080/ )而不是文件系统(例如
file:///C:/Users/...
)。
I did that by downloading http-server
with npm
and ran everything on the above server--but I still get that error.我通过使用
npm
下载http-server
并在上述服务器上运行所有内容来做到这一点 - 但我仍然遇到该错误。
Edit:编辑:
Failed import statement import axios from './node_modules/axios';
失败的导入语句
import axios from './node_modules/axios';
You might need type="module"
on your script
tag.您的
script
标签上可能需要type="module"
。 See: https://www.sitepoint.com/using-es-modules/请参阅: https : //www.sitepoint.com/using-es-modules/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.