简体   繁体   English

即使我在本地服务器上运行我的代码,也会出现“无法加载模块脚本...”

[英]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.

相关问题 加载模块脚本失败:应为 JavaScript 模块脚本,但服务器响应 MIME 类型为“”。 (我做了类型模块) - Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "". (I did type module) 即使有资源也无法加载 - Failed to load resource even though it is there 即使我在后台运行了模拟器,也无法运行我的React本机代码 - I can't run my react native code even though I have an emulator running in the back round 即使我的代码中有catch部分,我仍收到未处理的Promise Rejection错误 - I am getting Unhandled Promise Rejection error even though I have the catch section in my code 如何从我的网页运行本地服务器脚本? - how can i run a local server script from my webpage? 当我想在本地服务器上运行我的代码时,我总是会收到这种错误“SyntaxError: Cannot use import statement outside a module” - When I wants to run my code in local server i always get this kinds of error “SyntaxError: Cannot use import statement outside a module” 即使我更改了权限,也无法加载资源:服务器的响应状态为403(禁止) - Even i change permissions i m getting Failed to load resource: the server responded with a status of 403 (Forbidden) Python Flask - 错误:“加载模块脚本失败。强制执行严格的 MIME 类型检查”。 适用于生产环境,而不是本地服务器 - Python Flask - Error: "Failed to load module script. Strict MIME type checking is enforced". Works on production, not on the local server 即使我的代码看起来很好,我仍然会收到“未捕获的TypeError:字符串不是函数”错误。任何人都可以看看并解释一下吗? - I keep getting a “Uncaught TypeError: string is not a function” error, even though my code seems to be fine. Can anyone have a look and explain? 即使我添加了请求模块,也会收到“错误:找不到模块‘请求’” - Getting "Error: Cannot find module 'request'" even though I have added request module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM