我正在尝试使用system.js将打字稿模块导入另一个文件,但在导入时必须指定js扩展名。
这是我的app.ts文件
import {PI, calculateCircumference} from "./math/circle.js";
console.log(PI);
console.log(calculateCircumference(10));
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Typescript</title>
<script src="node_modules/systemjs/dist/system.js"></script>
</head>
<body>
<script>
System.import('/app.js');
</script>
</body>
</html>
当我尝试在index.html中使用以下代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Learning Typescript</title>
<script src="node_modules/systemjs/dist/system.js"></script>
</head>
<body>
<script>
System.config({
baseURL : '/',
defaultJSExtensions : true
});
System.import('/app.js');
</script>
</body>
</html>
TypeError:System.config不是函数
我要去哪里错了?
这是我的packages.json文件
{
"name": "typescript",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "lite-server"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lite-server": "^2.4.0"
},
"dependencies": {
"browser-sync": "^2.26.3",
"systemjs": "^2.0.2"
},
"keywords": [],
"description": ""
}