Angular-将本地外部模块添加到App

威廉

我有一个项目my-components和一个项目my-showcasemy-components是Angular库,my-showcase是Angular应用程序。有时,当我在库中更改或添加组件时,我将提交到private git并发布到private npm。然后,我可以在其他应用程序(例如my-showcase)中使用它在提交和发布之前,我将对其进行测试。到目前为止,我在自己的展示柜中创建和开发一个新组件。完成后,我将其放入my-components中

当时我通过npm导入了我的角度分量库:

import {TimePickerModule} from '@company/components';

为了进行测试和开发,我将其更改为本地路径:

import {TimePickerModule} from '../../../../company-components/projects/components/src';

不幸的是,我收到以下错误消息:

WARNING in ../company-components/node_modules/@angular/core/fesm5/core.js 15153:15-36
Critical dependency: the request of a dependency is an expression

和:

core.js:12584 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[DcStickyBitsDirective -> ElementRef]:
  StaticInjectorError(Platform: core)[DcStickyBitsDirective -> ElementRef]:
    NullInjectorError: No provider for ElementRef!

显然,应用程序my-showcase中来自库的组件使用了my-components中的错误的node_module文件夹(特别是@ angular / core),而不是my-showcase中的node_module文件夹

在处理Angular Library和NPM时,有人对我有解决方案吗?如果太难以理解,请告诉我。

威廉

我有一个解决方法。我在tsconfig.json中添加以下内容

"@company/components": [
    "../path/to/projects/components/src"
],

"@angular/*": [
    "node_modules/@angular/*"
]

但是我发现这种解决方案不是很干净。如果我理解正确,那么问题是Webpack从组件库而不是展示项目中获取Angular的东西。通过这种解决方法,它可以覆盖错误的路径。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章