[英]React prop-types error
I'm trying to create web app in codepen.我正在尝试在 codepen 中创建网络应用程序。 I'm using React, ReactDOM.我正在使用 React,ReactDOM。 All was fine.一切都很好。 But when I added react-router-dom to my project, I got an error:但是当我将 react-router-dom 添加到我的项目时,出现错误:
react-router-dom.min.js:1 Uncaught Error: Cannot find module "prop-types"
How can I fix this?我怎样才能解决这个问题?
As of React 15.5.0, PropTypes have been removed from the core React package as a separate dependency.从 React 15.5.0 开始,PropTypes 已作为单独的依赖项从核心 React 包中删除。 To fix this, add prop-types
into your code:要解决此问题,请将prop-types
添加到您的代码中:
If you're loading via script tags:如果您通过脚本标签加载:
<script src="https://unpkg.com/prop-types/prop-types.min.js"></script>
Or via NPM:或者通过 NPM:
npm install --save prop-types
Looks like the lates UMD build at:看起来最新的 UMD 构建在:
<script src="https://unpkg.com/react-router-dom/umd/react-router-dom.min.js"></script>
is currently missing a dependence on prop-types.目前缺少对道具类型的依赖。 You can use version 4.0.0 instead for the time being to avoid this error:您可以暂时使用 4.0.0 版本来避免此错误:
<script type="text/javascript" src="https://unpkg.com/react-router-dom@4.0.0/umd/react-router-dom.min.js"></script>
This is due to prop-type being missing.这是因为缺少 prop-type。 It can be added using your package manager.可以使用您的包管理器添加它。
If you're using npm:如果您使用的是 npm:
npm install prop-types --save
If you're using yarn:如果您使用纱线:
yarn add prop-types
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.