类不是Angular模块-仅在导入本地构建的Angular库时在IntelliJ / Webstorm中 [英] Class is not an Angular module - only in IntelliJ/Webstorm when importing locally build Angular library

查看:313
本文介绍了类不是Angular模块-仅在导入本地构建的Angular库时在IntelliJ / Webstorm中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用在单独的Angular应用程序中存在的库(项目)中实现的Angular模块。在IntelliJ中,我收到错误 Class MyModule不是Angular模块,并且在我可以成功运行 ng时,IntelliJ中似乎无法识别所有库为该项目构建。更奇怪的是,我实际上在另一个Angular应用程序中存在两个Angular库,并且我可以毫无问题地使用另一个库中的模块。

I am trying to use Angular module implemented in a library (project) which exists in a separate Angular application. In IntelliJ I am getting an error Class MyModule is not an Angular module and all the library seems to not be recognized in IntelliJ while I can successfully run ng build for this project. Whats even more weird is that I have actually two Angular libraries existing in the other Angular app and I can use modules from the other library without issues.

我已经访问了另一个类似地,与 class相关的问题不是Angular模块,但似乎与它们无关。

I've visited other similarly looking problems related to class is not an Angular module yet they does not seem to be related.

推荐答案

这是我绕了几个小时后发现的答案。在主项目中如何使用有问题的库是

Here is an answer I found after a few hours of wrapping my head around. How I use the problematic library in the main project is:


  • npm链接 lib的 build 文件夹

  • npm链接@ my-org / my-new-lib 在应用程序中我看到了问题。

  • npm link in the build folder of the lib
  • npm link @my-org/my-new-lib in the app I see issues.

以及 ng build @ my-org / my-new-lib --watch for lib,这使我可以同时处理两个项目,并立即在目标应用程序中看到结果。

along with ng build @my-org/my-new-lib --watch for the lib this allows me to work on both project at the same time seeing instantly results in the target app.

问题显然是由于IntelliJ中的错误- https://youtrack.jetbrains.com/issue/WEB-38354?_ga=2.263408847.258701770.1571260138-1443411092.1565629801 -它导致路径中带有 dist 的依赖项即使该库已正确链接到目标应用程序的 node_modules ,IntelliJ也会自动将其排除在外,因此IntelliJ排除了它,因此该库实际上不是

The issue is apparently due to a bug in IntelliJ - https://youtrack.jetbrains.com/issue/WEB-38354?_ga=2.263408847.258701770.1571260138-1443411092.1565629801 - it is causing dependencies with dist in the path to be automatically exculded to even though the library is correctly linked into the target app's node_modules IntelliJ is excluding it thus the library is in fact not usable in the IDE.

解决方法(类似于jetbrains票证中建议的一种方法)是在目标应用程序的IDE中进入符号链接的 node_modules / @ my-org / my-new-lib -右键单击它,然后选择标记目录为-> 未排除

The workaround (similar to the one suggested in the jetbrains ticket) is to go in the IDE in the target app to the symlinked node_modules/@my-org/my-new-lib - right click on it and choose Mark Directory as -> Not Excluded

希望这可以为某人节省一些时间,因为它确实令人困惑且难以克服。

Hope this may save some time to someone as it was really confusing and non obvious to overcome.

这篇关于类不是Angular模块-仅在导入本地构建的Angular库时在IntelliJ / Webstorm中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆