React prop-types error
Asked Answered
D

4

13

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?

Dumyat answered 11/4, 2017 at 22:53 Comment(3)
Add the missing dependencies... See also the dependencies section in npmjs.com/package/react-router-domDuprey
Please see: How do I avoid misusing tags?Collage
I use npm but not cnpm and yarn,it works!Typesetting
S
26

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
Staghound answered 12/4, 2017 at 2:33 Comment(0)
R
7

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
Retharethink answered 7/2, 2018 at 17:33 Comment(1)
When adding an answer to an older question with existing accepted answers it can be helpful to point out what new information your answer brings to the question.Dutyfree
F
3

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/[email protected]/umd/react-router-dom.min.js"></script>
Frumpish answered 12/4, 2017 at 1:9 Comment(0)
J
0

This solved for me:

npm install @types/prop-types
Jimmy answered 4/8 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.