React prop-types error

2019-04-11 05:39发布

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?

3条回答
Deceive 欺骗
2楼-- · 2019-04-11 05:59

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>
查看更多
Bombasti
3楼-- · 2019-04-11 06:07

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
查看更多
疯言疯语
4楼-- · 2019-04-11 06:13

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
查看更多
登录 后发表回答