小编Sk_*_*oat的帖子

“导入”语句在呈现的 HTML 中的脚本中不起作用

我正在开发一个快速应用程序,我正在尝试执行以下操作,但我一遍又一遍地遇到相同的错误 - “GET http://localhost:3000/javascript/module2 net::ERR_ABORTED 404 (Not Found)”

有人可以向我指出我犯了什么错误并指出我正确的方向吗?下面是我的代码 -

模块1.js

import theFunc from "./module2";
console.log("In module 1");
theFunc();    
Run Code Online (Sandbox Code Playgroud)

模块2.js

export default function theFunc() {
console.log("from module 2");
}
Run Code Online (Sandbox Code Playgroud)

索引.html

<html>
 <body>
   Should show the result in console.
  <script type="module" src="./javascript/module1.js"></script>
 </body>
</html>
Run Code Online (Sandbox Code Playgroud)

提前致谢!:)

javascript node.js express ecmascript-6 es6-modules

5
推荐指数
2
解决办法
2721
查看次数

标签 统计

ecmascript-6 ×1

es6-modules ×1

express ×1

javascript ×1

node.js ×1