MonorePo(Lerna)软件包中的一个React应用程序,导致冲突' React'包裹

发布于 2025-01-29 00:43:37 字数 279 浏览 5 评论 0原文

我创建了:

  • 可重复使用的React组件软件包,以及
  • 用于测试组件的React应用程序

两者都在MonorePo(Lerna)内。 问题是组件的“反应”软件包&因为该应用指向“不同的事物”,因此使用组件内的钩子会触发此错误: “钩子只能在功能组件的主体内部调用”。

删除第二个“ React”软件包目录将对组件项目产生影响,因为它是符号链接(类似于组件项目的快捷方式)。 解决我的问题的任何想法吗? png“ alt =”在此处输入图像说明”>

I created :

  • A reusable react component package, and
  • A react app for testing the component

Both of them are inside a monorepo (lerna).
The problem is the "react" packages for the component & for the app are pointed to "different thing", thus using hook inside the component triggers this error:
"Hooks can only be called inside the body of a function component".

Deleting the second "react" package directory will affect to the component project because it's a symbolic linking (similar to shortcut to component project).
Any idea for resolving my problem?enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我一向站在原地 2025-02-05 00:43:37
  1. 清洁所有node_modules。
  2. 在React组件中使用同行依赖项。

l使用Monorepo中的两个步骤slove React版本冲突问题。
您可以尝试。

  1. clean all the node_modules.
  2. use peer dependencies in react component.

l use that two steps slove react version conflict problem in monorepo.
You can try it.

若水微香 2025-02-05 00:43:37

步骤1
清除所有节点模型,DIST文件

步骤2
则步骤到root文件夹并使用-npx lenda run构建

如果您仍在面对此问题, 。根据您的要求更改TSCONFIG文件。

Step-1
Clear all node-modules, dist files

Step-2
Step to root folder and procced with - npx lerna run build

If you are still facing this issue. Change the tsconfig file based on your requirements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文