![](/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.