首页 > 解决方案 > Typescript:使用 ng-packagr 编译 Angular 9 项目时出现冲突的命名空间警告

问题描述

我不确定这个问题到底应该归咎于什么。我认为它是 Typescript,但它可能是 ng-packagr 或 Angular。它只是在我更新到 Angular 9 时才开始的。

这是我在生产构建中收到的消息...

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)

这是导致此问题的来源之一...

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

编译器出于某种原因获取函数参数并将其分配给 aconst然后像这样导出它......

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

我的问题是,为什么ɵ0需要导出?它仅在此文件内部使用。我错过了什么吗?应该担心这个吗?使用使用此代码构建的库时,它似乎不会导致问题。

标签: angulartypescriptcompilationcompiler-warningsng-packagr

解决方案


我在更新到 Angular 9 时收到了同样的警告,在网上寻找一些信息/解决方案我还发现了这个 Angular 问题页面https://github.com/angular/angular/issues/33668(11/2019所以3个月前),他们说这是常春藤的问题,与“出口*”有关。

这很奇怪,因为我需要发布到 npm 并且构建建议说要禁用 Ivy,所以我禁用了它( tsconfig.lib.json 中的 angularCompilerOptions.enableIvy false ):相反,将 enableIvy 设置为 true 会使警告消失。

所以我做了这个尝试,同时在 tsconfig.lib.json 中将 enableIvy 设置为 false,在 public-api.ts 中,我修改了“export *”,用所有导出的对象一一替换了“*”:警告消失了,图书馆正在工作。

但我真的不知道这是否是一个很好的解决方案,或者只是显示警告是否更好..


推荐阅读