我一直在研究打字稿。
我在研究节点模块时遇到以下错误。
单击匿名函数会将我带到下面的代码。
<!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')
// hmmtsconfig.json
:使用"module": "system"
代替"module": "commonjs"
。app.ts
:使用import { PI, calculateCircumference } from "./maths/circle.js";
代替import { PI, calculateCircumference } from "./maths/circle";
// hmm
(我找不到配置baseUrl
或defaultExtension
的方法)
在浏览器上重新加载html页面之前,运行tsc
命令重建app.js
文件。