Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在typescript中的模块导入中默认使用JS扩展_Typescript_Systemjs - Fatal编程技术网

在typescript中的模块导入中默认使用JS扩展

在typescript中的模块导入中默认使用JS扩展,typescript,systemjs,Typescript,Systemjs,我试图使用system.js将typescript模块导入到另一个文件中,但我必须在导入时指定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

我试图使用system.js将typescript模块导入到另一个文件中,但我必须在导入时指定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>

我认为只有SystemJS版本0.x才支持
System.config
,而您使用的是SystemJS 2.x。所以,如果js扩展是默认的,那么应该怎么做呢。新的做法是什么?
<!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>
{
  "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": ""
}