问题描述
我有一个React函数组件SimpleComponent
,它是从library
项目中导出并发布在GitHub软件包上的。该软件包在consumer
项目中使用,该项目仅呈现SimpleComponent
。如果SimpleComponent
使用React钩子,它将无法在consumer
项目中呈现,并且出现以下与React钩子相关的错误:
Uncaught Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
library
项目:https://github.com/joshigaurava/library consumer
项目:https://github.com/joshigaurava/consumer
两个项目都使用React,TypeScript和webpack。包括Package.json,TypeScript和webpack配置。
library
软件包版本0.0.1
包含SimpleComponent
,没有React钩子,并且在consumer
项目中可以正常渲染和运行。 (SimpleComponent
works)
library
软件包版本0.0.2
包含带有React钩子的SimpleComponent
,并且无法在consumer
项目中呈现。 (SimpleComponent
fails)
我看到许多其他人都面临着类似的问题,到目前为止,我已经尝试了各种方法,但是没有任何效果:
- 确保
consumer
项目(npm ls react
,npm ls react-dom
)中对react / react-dom的依赖是唯一的 - 确保没有发生https://reactjs.org/warnings/invalid-hook-call-warning.html列出的所有问题
- 在依赖项中使用
npm link
时,人们似乎已经用npm file:
或符号链接解决了这个问题,但就我而言,consumer
项目正在通过消耗{ npm软件包,因此这不适用 - 愚蠢地尝试以不同方式导出
library
-带有或不带有SimpleComponent
等。
现在,我想知道这是否与webpack如何捆绑default
项目有关。但是我在这个问题上花费了太多时间,我们将不胜感激。
解决方法
webpack配置是问题所在。 React被捆绑在输出中。对于任何在此问题上遇到困难的人,以下webpack配置有助于解决此问题:
yourdf = df2.merge(df1.rename(columns={'ID' : 'Opponent'}),on = ['Opponent','Round'],how = 'left')