简体   繁体   English

打字稿:使用 ng-packagr 编译 Angular 9 项目时出现命名空间冲突警告

[英]Typescript: conflicting namespaces warning on Angular 9 project compilation with ng-packagr

I am unsure what is really to blame for this issue.我不确定这个问题的真正原因是什么。 I think it's Typescript, but it could be ng-packagr or Angular.我认为它是 Typescript,但它可能是 ng-packagr 或 Angular。 It only started when I updated to Angular 9.它仅在我更新到 Angular 9 时才开始。

Here is the message I get on my production build...这是我在生产构建中收到的消息...

WARNING: Conflicting namespaces: dist/web-apps-shared/esm2015/public_api.js re-exports 'ɵ0' from both dist/web-apps-shared/esm2015/lib/api-applications/reducers.js and dist/web-apps-shared/esm2015/lib/account-codes/reducers.js (will be ignored)

Here is one of the sources that is causing this...这是导致这种情况的来源之一......

export const selectTotalAccountCodes = createSelector(selectSharedAccountCodeState,
  (state: SharedAccountCodeState) => state.totalItems);

The compiler for some reason takes the function parameter and assigns it to a const and then exports it like so...编译器出于某种原因接受函数参数并将其分配给一个const ,然后像这样导出它......

const ɵ0 = (state) => state.totalItems;
export const selectTotalAccountCodes = createSelector(selectSharedAccountCodeState, ɵ0);
export { ɵ0 };

The question I have is, why does ɵ0 need to be exported?我的问题是,为什么ɵ0需要导出? It is only used internally in this file.它仅在此文件内部使用。 I am I missing something?我错过了什么吗? Should worry about this?应该担心这个吗? It doesn't seem to be causing an issue when consuming the library that is built with this code.在使用使用此代码构建的库时,它似乎不会引起问题。

I've got the same warning while updating to Angular 9, looking on the web for some info/solutions I've also found this Angular issue page https://github.com/angular/angular/issues/33668 ( 11/2019 so 3 months ago ), where they say that is an Ivy's issue, something related to the "export * ".我在更新到 Angular 9 时收到了同样的警告,在网上寻找一些信息/解决方案我还发现了这个 Angular 问题页面https://github.com/angular/angular/issues/33668 ( 11/2019所以3个月前),他们说这是常春藤的问题,与“出口*”有关。

This is strange since I need to publish to npm and build recommendation says to disable Ivy , so I've disabled it ( angularCompilerOptions.enableIvy false in tsconfig.lib.json ): instead, set enableIvy to true makes the warning disappear.这很奇怪,因为我需要发布到 npm 并且构建建议说禁用 Ivy ,所以我已经禁用了它( tsconfig.lib.json 中的 angularCompilerOptions.enableIvy false ):相反,将 enableIvy 设置为 true 会使警告消失。

So I did this try, while keeping enableIvy set to false in tsconfig.lib.json, in the public-api.ts I've modified the "export * " replacing the "*" with all the exported objects, one by one: warning is gone, the library is working.所以我做了这个尝试,同时在 tsconfig.lib.json 中将 enableIvy 设置为 false,在 public-api.ts 中,我修改了“export *”,将“*”替换为所有导出的对象,一一:警告消失了,图书馆正在工作。

But I really don't know if this is a good fix or if it is better just to show the warnings..但我真的不知道这是否是一个好的解决方案,或者只是显示警告是否更好..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM