[英]import of library works in javascript file but fails in typescript file
我對 Javascript 很陌生,我需要修改舊代碼。 我正在嘗試將新模塊 @microsoft/applicationinsights-web 導入我的文件 test.ts 。 不幸的是,即使該模塊存在於 node_modules 中,它也會說找不到模塊。
一旦我將文件重命名為 test.js ,它就會開始工作。 請找到我的 tsconfig.json
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types"
],
"allowJs": true
}
}
這里有什么幫助嗎?
您的 tsconfig 似乎配置得不是很好。 復制此配置,它應該可以工作,請注意您的構建將在 dist 文件夾中,您必須從那里運行應用程序或使用 ts-node。
"compilerOptions": {
"outDir": "./dist",
"module": "commonjs", // classic format that Node.js understands
"esModuleInterop": true,
"lib": ["es6", "dom"], // use JavaScript API ES6
"target": "es6", // compile to ES6
"allowJs": true, // allow import of JS modules
"types": ["node"]
}
例如,它錯過了節點類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.