简体   繁体   English

导入自定义 Angular 库时,Angular 12 和 Webpack 5“找不到导出的节点名称”

[英]Angular 12 & Webpack 5 "Failed to find exported name of node" when importing custom Angular library

I'm currently migrating a big Angular application to Webpack 5 and started getting this error:我目前正在将一个大型 Angular 应用程序迁移到 Webpack 5 并开始收到此错误:

Compiling MyLib : main as umd
[webpack-cli] Error: Failed to find exported name of node (MonthViewComponent = /** @class */ (function (_super) {
        __extends(MonthViewComponent, _super);
        function MonthViewComponent(config) {
            var _this = _super.call(this) || this;
            _this.config = config;
            _this.openDayView = new i0.EventEmitter();
            return _this;
        }
  ...
  ..
  .

Basically, the error appears for any component or directive I use in the library itself but do not export in public-api.ts .基本上,我在库本身中使用但不在public-api.ts中导出的任何组件或指令都会出现错误。 If I export one of these internal components though, Webpack doesn't complain anymore about this one but the next internal component, and there are many of them.如果我导出其中一个内部组件,Webpack 不会再抱怨这个,而是下一个内部组件,而且其中有很多。 This used to work fine.这曾经工作得很好。

I've read similar questions about this exact error in Stackoverflow and Github but none of them offered a proper solution or those solutions didn't work in my case.我已经在 Stackoverflow 和 Github 中阅读过关于这个确切错误的类似问题,但它们都没有提供适当的解决方案,或者这些解决方案在我的情况下不起作用。

MyLib is installed locally: MyLib 安装在本地:

"dependencies": {
  "mylib": "file:/Users/brunofenzl/Projects/MyLib/dist/components",
  ...
}

I can confirm it is properly installed with npm list mylib我可以使用npm list mylib确认它已正确安装

app@1.162.0-rc.0 /Users/brunofenzl/Projects/app
└── mylib@17.0.1-beta.0 -> ./../MyLib/dist/components

Currently using目前使用

  • @angular/* 12.2.13 @角/* 12.2.13
  • @ngtools/webpack: 12.2.13 @ngtools/webpack:12.2.13
  • webpack: 5.72网络包:5.72
  • webpack-cli: 4.92 webpack-cli:4.92

Any idea what could be causing this?知道是什么原因造成的吗? Any help is more than appreciated!任何帮助都非常感谢!

So the issue was that tsc wasn't finding the corresponding types for this library.所以问题是tsc没有为这个库找到相应的类型。 I fixed it by adding the library name to the typeRoots property in my tsconfig.json file.我通过将库名称添加到我的 tsconfig.json 文件中的typeRoots属性来修复它。 This way the compiler found the appropriate typings in the library directory.这样,编译器在库目录中找到了适当的类型。

"typeRoots": [
  "typings",
  "node_modules/@types/",
  "libraryname",
],

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

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