angular - 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
需要导出?它仅在此文件内部使用。我错过了什么吗?应该担心这个吗?使用使用此代码构建的库时,它似乎不会导致问题。
解决方案
我在更新到 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 *”,用所有导出的对象一一替换了“*”:警告消失了,图书馆正在工作。
但我真的不知道这是否是一个很好的解决方案,或者只是显示警告是否更好..
推荐阅读
- r - 如何使用 download.file() 遍历列中的 url
- java - 如何通过 JSP 使用用户输入数据创建和查看会话密钥
- typescript - 如何在 React-leaflet 版本 3 中为同一位置添加多个图标
- java - 从 Firebase 中的子节点检索数据并使用构造函数类显示为 TextView
- algorithm - 计算给定数组中子数组的数量,其平均值为 k
- python - 与服务器建立连接后不打印到控制台
- java - 使用 JDK 11 的 PowerMockRule
- terminal - 我们如何使用 find 命令从列表中排除给定目录和子目录
- flutter - 找不到具有以下 ID 的广告。Natiev 广告颤振 google_mobile_ads
- javascript - 无法访问 API 时 catch 不起作用