react-native: PropTypes from React package on 0.45.1 release builds failing

Release builds are failing for Android on the 0.45.1 release of React Native. I’ve only tested this on Android, but I suspect the same is true for iOS.

Lines such as var ReactPropTypes = require('React').PropTypes; in LayoutPropTypes.js (among several others) are causing this.

The result is a crash on startup with a js exception: com.facebook.react.common.JavascriptException: undefined is not an object (evaluating 'ReactPropTypes.shape'), stack:

I’m aware that this is fixed on the master branch. I thought I would report this issue still, as it effectively cripples the 0.45.1 release and I need to release against master to make our app release builds work.

@andrewimm I see you fixed these lines on master, maybe you know what is going on here?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 19 (1 by maintainers)

Most upvoted comments

for me running the following fixed it without additional clean:

npm install react@16.0.0-alpha.12

@stoffern @tuneZola Just to help clarify this discussion. The issue is not wrong usage of the prop-types package by implementers. If you have prop-types in your package.json, it does not resolve the issue. The issue is wrong usage of prop-types from the React package in the React Native Libraries;

Basically, there is a mismatch between the React package ^16.0.0-alpha.12 and the React Native package 0.45.1. This is the default combination if you upgrade your project to 0.45.1, causing the issue. In the React Native codebase, there are references to both React.createClass and to import {PropTypes} from 'react'; Just search for it in your node_modules/react-native/Libraries if you do not feel that this could be true.

You can work around this by either downgrading the react version to pre-16, but I don’t know what the potential impact is of that, I haven’t tried it. Or using the non-released React Native code from master, where the references to React.createClass and PropTypes} from 'react' are already removed, at your own risk. 😃

It is seperated from react…

install

npm i -S prop-types

import

import PropTypes from 'prop-types'; // ES6 
var PropTypes = require('prop-types'); // ES5 with npm 

more info: https://www.npmjs.com/package/prop-types

Same for me. If React 16 alpha is the “supported” version for React Native 0.45.1, I really don’t know how can var ReactPropTypes = require('React').PropTypes; be in the code.

@bartolkaruza Did you read the link that I posted? This was the start of the moving of those two items. If you are used React 16.0.0, PropTypes and createClass are not in the React package anymore. You will have to change back to React 15.6.1 or some other 15.* package.

@tuneZola the crash is happening in the RN codebase, not our app code base. Also, the same was happening for React.createClass calls in the RN codebase. This is on RN 0.45.1 with the recommended React version;

People will run into this issue if they upgrade to RN 45.1. Similar issues are being raised like https://github.com/facebook/react-native/issues/14590 .

Maybe it would be a good idea to cut another release that fixes this soon?

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

@bartolkaruza I’m not sure, but it seems like i finally got it working (though I only tried it on my emulator).

what I did was:

  1. ran react-native-git-upgrade (though I already had 45.1, just in case)
  2. cleaned up gradle ./gradlew clean
  3. reinstalled my app npm dependencies (again, just in case)

I guess something changed in the packages, which are upgraded on the first step, or, maybe, some old libraries were somehow cached. Now it runs ok, at least on my emulator. I also did not try it with release builds, but at least it helped to continue my development. And logs still show some warnings about PropTypes (though we’ve set them up correctly according to migration guide), maybe because of some libraries.

@bartolkaruza If you are using react >=15.5 you should change to prop-types package.

https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html