26

After deleting and reinstalling my node_modules folder, I'm facing an issue that I don't understand in LayoutPropTypes.js file.

In node_modules/react-native/Libraries/StyleSheet/LayoutPropTypes.js The following variable is undefined : var ReactPropTypes = require('React').PropTypes;

react-native: 0.45.1 react: 16.0.0-alpha.12

6 Answers 6

41

React.PropTypes is now deprecated:

Note: React.PropTypes is deprecated as of React v15.5. Please use the prop-types library instead.

You need to add the prop-types package separately now. The error most likely just started to show up because you deleted your node_modules folder and then reinstalled everything which upgraded your react version.

Sign up to request clarification or add additional context in comments.

3 Comments

I have added prop-types into my project, but I still have this problem. I tried to reinstall node, it was no use. And now, I even couldn't run the demo of react native. I want to know how can I degrade the version of react?
Fixed by restarting computer :(
@NicolasMeienberger yarn add [email protected]
15

React is no more shipped with PropTypes. You will need to install it.

First install the prop-types package by running npm i prop-types --save.

Next use the prop-types package into your component like this:

import React from 'react'
import PropTypes from 'prop-types'

export const AwesomeComponent = props => {
    return(
        <h1>Hello {props.name}</h1>
    )
}

AwesomeComponent.propTypes = {
    name: PropTypes.string.isRequired
}

Or simply use an interface if you are using Typescript like this:

import * as React from 'react'

interface IAwesomeComponentProps {
    name: string
} 

export const AwesomeComponent: React.FC<IAwesomeComponentProps> = props => {
    return(
        <h1>Hello {props.name}</h1>
    )
}

Comments

11

Are you absolutely sure you are using react 16.0.0-alpha.12?

Check your package.json if you have a ^ before the react version, if you have, it probably have installed the latest react version, which currently is 16.0.0-alpha.13, in which it breaks as you say (just had the problem myself). Having the ^ before the version, allows it to install newer minor and patch versions. You can read more about it here.

To keep it at the exact version you specify, simply remove the ^ before the version, so that your package.json looks like this:

  "dependencies": {
    "react": "16.0.0-alpha.12",
    "react-native": "0.45.1",
  }

Remember to re-install your node_modules after your changes.

1 Comment

I have the same issue in alpha.13, when back to alpha.12 is OK!
2

I have the similar problem, no solution. Answers talking about 'prop-types' package are meaningless, the problem is come from react-native source code. That is not an option to manually fix react native source in node_modules folder.

1 Comment

What I do not fully understand, if I create a fresh app with react-native init then the app runs well.
1

Now you can update to react-native 0.46.4, just follow along this guide: https://facebook.github.io/react-native/docs/upgrading.html

my package.json looks like this:

"react": "16.0.0-alpha.12",
"react-native": "0.46.4",

Comments

0

instead of defining the value for component as like this: propName: React.PropTypes.string

DEFINE LIKE THIS propName: PropTypes.string

and finally save it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.