我一直在研究打字稿。
我在研究节点模块时遇到以下错误。

javascript - 如何解决“未处理的 promise 拒绝:错误:无法从http://localhost:3000/解析裸指定符“app.js””-LMLPHP

单击匿名函数会将我带到下面的代码。

javascript - 如何解决“未处理的 promise 拒绝:错误:无法从http://localhost:3000/解析裸指定符“app.js””-LMLPHP

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="author" content="">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Learning TypeScript</title>
    <script src="node_modules/systemjs/dist/system.js"></script>
</head>

<body>
    <script>
        System.import('app.js')
    </script>
</body>

</html>


这是指向我的demo project的链接

最佳答案

如果您使用的是最新版本的SystemJS。您必须进行一些更改:


index.html:使用System.import('./app.js')代替System.import('app.js') // hmm
tsconfig.json:使用"module": "system"代替"module": "commonjs"
app.ts:使用import { PI, calculateCircumference } from "./maths/circle.js";代替import { PI, calculateCircumference } from "./maths/circle"; // hmm


(我找不到配置baseUrldefaultExtension的方法)

在浏览器上重新加载html页面之前,运行tsc命令重建app.js文件。

09-20 23:15