[英]How to compile Typescript to JS that uses ES6 modules?
我的tsconfig.json
文件包含
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
}
}
但是編譯后的 JS 文件仍然使用exports
/ require
語法。
我該如何解決?
編輯:
我的目錄結構如下
- APIs/
- emails/
- sendEmail.ts
- oldFiles/
- file1.js
- file2.js
- index.js
- tsconfig.json
- package.json
我正在使用根目錄中的命令tsc APIs/emails/sendEmail.ts
運行tsc
。
這些設置是正確的,因此很可能您實際上並未使用該tsconfig.json
文件。 例如,如果您執行tsc someFile.ts
,則tsc
不使用tsconfig.json
(令人驚訝)。 您最好的選擇可能是在您的配置中添加一個includes
(以便tsc
知道它正在編譯什么),然后通過調用tsc
進行編譯,這將查找本地tsconfig.json
。
{
"compilerOptions": {
"module": "esnext",
"target": "esnext"
},
"include": ["**/*.ts"]
}
然后在package.json
中(例如):
// ...
"scripts": {
"build": "tsc"
}
// ...
這個配置應該可以工作。 但它是tsconfig.json
而不是tsconfig.js
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.