Angular 7多个库依赖项

时间:2019-04-10 13:14:01

标签: angular

我正在Angular 7中创建一个包含许多库的共享项目。当我在2个库之间有依赖关系时,会出现此错误

BUILD ERROR
Could not resolve entry (C:\development\WorkOrder.Shared.Client.Web\dist\icons\esm2015\my.library.workflows-icons.js)
Error: Could not resolve entry (C:\development\WorkOrder.Shared.Client.Web\dist\icons\esm2015\my.library.workflows-icons.js)
    at error (C:\development\WorkOrder.Shared.Client.Web\node_modules\rollup\dist\rollup.js:3460:30)
    at C:\development\WorkOrder.Shared.Client.Web\node_modules\rollup\dist\rollup.js:21474:17

Could not resolve entry (C:\development\WorkOrder.Shared.Client.Web\dist\icons\esm2015\my.library.workflows-icons.js)
Error: Could not resolve entry (C:\development\WorkOrder.Shared.Client.Web\dist\icons\esm2015\my.library.workflows-icons.js)
    at error (C:\development\WorkOrder.Shared.Client.Web\node_modules\rollup\dist\rollup.js:3460:30)
    at C:\development\WorkOrder.Shared.Client.Web\node_modules\rollup\dist\rollup.js:21474:17

我尝试了所有事情。其中之一是将tsconfig.lib.json文件的路径添加到我有依赖关系的库中。 但是错误仍然存​​在

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,花了几个小时找出解决方案。最后,我进行了以下更改以解决此问题
假设library2依赖于library1

  • 在同一库中使用相对路径导入模型
    使用VSCode时,有时会自动修复并自动导入模块,路径为
   import { something } from 'libary2/lib/models'

应更改为

   import { something } from '../../models';
  • 将library1的构建版本添加到library2的tsconfig.lib.json的路径中,还需要指定baseUrl
 "extends": "../../tsconfig.json",
 "compilerOptions": {
     "outDir": "./out-tsc/lib",
     "baseUrl": "./",
     ....
     "paths": {
       "library1": ["../../dist/library1"],
       "library1/*": ["../../dist/library1/*"],
     }
 }