简体   繁体   English

角度构建失败,因为它包含另一个角度项目中的组件

[英]Angular build fails because it includes components from another angular project

When I run ng build project1 --prod the build fails with the error message 当我运行ng build project1 --prod ,构建失败并显示错误消息

ERROR in : Cannot determine the module for class MyComponent in .../project2/app/my.component.ts! Add MyComponent to the NgModule to fix it. .

This seems pretty straight forward, BUT the mentioned Component is not part of the current Angular project. 这似乎很简单,但是提到的Component不是当前Angular项目的一部分。 I defined two projects inside my angular.json and they are not dependent of each other (project1 & project2). 我在angular.json中定义了两个项目,它们彼此不依赖(project1和project2)。 I've got a separate shared module which both projects import and use. 我有一个单独的共享模块,可以导入和使用项目。

The error appeared when I moved a component from project2 to my shared module. 将组件从project2移到共享模块时出现错误。 My project2 builds fine and the moved components also work fine. 我的project2构建良好,移动的组件也正常运行。 ng serve project1 works without problems. ng serve project1正常进行。 But for some reason, my first project now depends on most components from my second project for no reason. 但是由于某种原因,我的第一个项目现在毫无理由地依赖于第二个项目中的大多数组件。 I already searched all my imports for the file without success. 我已经在所有导入文件中搜索了文件,但没有成功。 Maybe it's related to the fact that the components from project2 extend a component from the shared module? 可能与project2中的组件扩展了共享模块中的组件有关吗?

So is there any way to see where angular thinks it needs this? 那么,有什么方法可以查看角度认为它需要它的地方吗? For example, I see the main chuck was build before - what is angular building when it fails? 例如,我看到主卡盘之前已经构建过-当它失败时,什么是角度构建?

Can I exclude this somehow ( tsconfig.app.json exclude didn't work)? 我可以以某种方式排除这种情况( tsconfig.app.json排除无效)吗?

I found an unused import which itself imported most of the other projects components. 我发现了一个未使用的导入,它本身导入了大多数其他项目组件。

But if anyone still knows a way to see which file caused this kind of error I would still appreciate it and accept it as the final answer. 但是,如果有人仍然知道查看哪个文件引起此类错误的方法,我仍然会感激并接受它作为最终答案。 I had to look into every single file to find the wrong import. 我必须查看每个文件才能找到错误的导入。

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

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