![](/img/trans.png)
[英]Angular/Typescript tsconfig.json configure path alias with multiple paths
[英]How to configure paths property in tsconfig.json file for external libraries
在[鏈接]中找到了我想要做的最接近的解釋。 不過,我仍在努力尋求解決方案來進行編譯。
我有我要在項目中使用的外部類型,並且所有類型都有.d.ts文件,其名稱空間為“ DS / ”,我將其存儲在名為“類型”的文件夾中。 下面是我簡單的Angular應用程序的文件夾結構。
-MyAppName --typings ----all my modules d.ts --src ----app -tsconfig.json
這是我的tsconfig.json文件,如下所示
"compileOnSave": false, "compilerOptions": { "baseUrl": ".", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleResolution": "node", "importHelpers": true, "target": "es2015", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2018", "dom" ], "paths": { "DS/*": [ "typings/*" ], "*": [ "src/*" ] } }, "include": [ "typings/**/*.ts" ], "exclude": [ "node_modules" ], "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true }
從“ DS / MyModuleName”導入{MyModuleName}時,導入庫出現錯誤。
./src/app/app.module.ts中的錯誤找不到模塊:錯誤:無法解析“ MyAppName \\ src \\ app”中的“ DS / MyModuleName”
我正在使用AngularCLI來構建應用程序。 我無法將tsconfig文件配置為支持這些外部導入的庫。 不知道我在做什么錯。 請幫忙。
根據您的樹,嘗試在您的tsconfig.ts中
"typeRoots": ["node_modules/@types", "typings" ]...
"paths": {
"DS/*": [
"typings/*"
],
}
"include": ["src", "typings"],
然后在你的app.module.ts中
import { MyModuleName} from 'DS/myModuleName.module';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.