[英]Invalid propTypes warning when used with a npm package
I've extracted some stuff from my react application into a separate npm package. 我已经从我的react应用程序中提取了一些东西到一个单独的npm包中。 Everything works, but I have some propTypes warnings I cannot get rid of and they were not there before the extraction.
一切正常,但是我有一些无法摆脱的propTypes警告,并且它们在提取之前不存在。
I'm using propTypes as follows: 我正在使用propTypes,如下所示:
MyClass.propTypes = {
mapField: PropTypes.instanceOf(Immutable.Map).isRequired,
};
The warning is: 警告是:
Warning: Failed prop type: Invalid prop `mapField` of type `Map`
supplied to `MyClass`, expected instance of `Map`.
Both the extracted npm package and the host application use the same versions for all the common dependencies. 提取的npm软件包和主机应用程序对于所有公共依赖项都使用相同的版本。
I am 100% sure that mapField
is an instance of Immutable.Map
. 我100%确定
mapField
是Immutable.Map
的实例。 The issue occurs for other classes as well, such as moment
, Immutable.List
. 该问题也发生在其他类上,例如
moment
, Immutable.List
。
Solved. 解决了。 The problem was I was not using
immutable
as a peerDependency in the npm module I've created. 问题是我没有在我创建的npm模块中使用
immutable
作为peerDependency。 Even though it had the same version, it did not work. 即使它具有相同的版本,也无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.