React prop-types error

笑着哭i 提交于 2019-12-06 05:51:26

问题


I'm trying to create web app in codepen. I'm using React, ReactDOM. All was fine. But when I added react-router-dom to my project, I got an error:

react-router-dom.min.js:1 Uncaught Error: Cannot find module "prop-types"

How can I fix this?


回答1:


As of React 15.5.0, PropTypes have been removed from the core React package as a separate dependency. To fix this, add prop-types into your code:

If you're loading via script tags:

<script src="https://unpkg.com/prop-types/prop-types.min.js"></script>

Or via NPM:

npm install --save prop-types



回答2:


Looks like the lates UMD build at:

<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:

 <script type="text/javascript" src="https://unpkg.com/react-router-dom@4.0.0/umd/react-router-dom.min.js"></script>



回答3:


This is due to prop-type being missing. It can be added using your package manager.

If you're using npm:

npm install prop-types --save

If you're using yarn:

yarn add prop-types


来源:https://stackoverflow.com/questions/43357501/react-prop-types-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!