简体   繁体   English

与npm软件包一起使用时,无效的propTypes警告

[英]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%确定mapFieldImmutable.Map的实例。 The issue occurs for other classes as well, such as moment , Immutable.List . 该问题也发生在其他类上,例如momentImmutable.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.

相关问题 React-Router npm包在控制台中给我警告? (不推荐使用PropTypes) - React-Router npm package giving me warning in console? (PropTypes deprecated) 关于警告:不赞成通过主React包访​​问PropType。 使用npm中的prop-types包 - Regarding Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead 使用 propTypes 验证时的条件渲染和警告 - Conditional rendering and warning when using propTypes validation 如何查找警告原因:PropTypes 已移至单独的包 - How to find cause of Warning: PropTypes has been moved to a separate package 已发布 npm package 警告修复 - published npm package warning Fix 链接 react-app 和本地 npm 包的无效挂钩调用警告 - Invalid Hook Call Warning Linking a react-app and a local npm package 开发 React NPM package 时出现“元素类型无效”错误 - Get 'Element type is invalid' error when developing a React NPM package PropTypes警告,即使react-if的condition属性为false时 - PropTypes warning even when react-if's condition attribute is false 传入图标数组时,propTypes 应该是一个 func 控制台警告 - propTypes should be a func console warning when passing in array of icons 电子应用中的propTypes警告 - propTypes warning in Electron app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM