我很难尝试导入模块A:
export module A {
export class A_Class {
}
}
进入我的模块B:
import { A } from "./a";
let a = new A.A_Class();
我的tsconfig.json
看起来像这样:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"compileOnSave": true,
"files": [
"a.ts",
"b.ts",
]
}
我的cshtml
有这个脚本部分:
<script type="module" src="~/Scripts/app/b.js"></script>
Chrome浏览器给出了错误:
http://localhost:64518/Scripts/app/a net::ERR_ABORTED 404 (Not Found)
对于line 1
上的b.js
:
import { A } from "./a";
我完全没有想法,并尝试过es6
,commonjs
等的许多组合,import
的错误只是变化了一点点。
我正在使用Typescript 3.0
。
尝试改变这个:
import { A } from "./a";
对此:
import { A } from "./a.js";
文件“a”实际上并不存在,因此Chrome无法找到它。但是,a.js
应该存在。
如果你在服务器后面运行它,或者如果你正在使用像SystemJS这样的模块加载器,你可能能够在没有文件扩展名的情况下向请求添加.js
,如果找不到文件,否则你需要在您的导入中手动输入扩展名。