[英]Can't import modules with Typescript
我很難導入模塊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)
對於b.js
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
添加到請求中,否則您將需要在導入中手動添加擴展名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.