Reputation: 6949
I'm running the unit tests in a react-native app I'm developing and three of them are failing with this message:
TypeError: Cannot read property 'ReactCurrentOwner' of undefined
The error does not seem to be caused by my code, but either by react-test-renderer
(in two tests) and in enzyme-adapter-react-16
(in one test).
This was an expo app and the unit tests were running. I then ejected. I replaced
"jest": {
"preset": "jest-expo"
},
with
"jest": {
"preset": "react-native"
},
and all my other tests are running. The three failing tests are the only ones that use react-test-renderer
and enzyme-adapter-react-16
.
I've tried (many times) removing node_modules
and reinstalling. Here are the versions I'm using:
"devDependencies": {
"babel-preset-react-native-stage-0": "^1.0.1",
"deep-freeze": "^0.0.1",
"enzyme": "^3.1.1",
"enzyme-adapter-react-16": "^1.0.4",
"eslint": "^4.9.0",
"jest": "^21.2.1",
"react-dom": "^16.0.0",
"react-test-renderer": "^16.0.0"
},
"scripts": {
"start": "react-native start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"test": "jest"
},
"jest": {
"preset": "react-native"
},
"dependencies": {
"assert": "^1.4.1",
"react": "16.0.0",
"react-native": "^0.50.1",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"yarn": "^1.3.2"
}*
Upvotes: 7
Views: 20597
Reputation: 66
For those using Expo and trying to update their React Native packages to the latest version – don't do what I did and manually update the packages (by doing pnpm up --latest
for example).
Expo relies on packages being a certain version. Therefore, to solve the issue in this case:
npx expo-doctor
npx expo install --check
If this still doesn't solve the issue, I would suggest performing a clean install of packages rm -rf node_modules
, clearing the cache (for eg pnpm store prune
), and trying the above steps again.
For those using a development build of expo, I'd suggest doing a clean prebuild npx expo prebuild --clean
before trying to start the dev server (for eg npx expo run:ios
).
Upvotes: 2
Reputation: 1520
Seems like you need to update react
, react-dom
and react-test-renderer
to 16.3.2
.
It seems like one of them is 16 alpha which is not officially supported yet.
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-test-renderer": "^16.3.2"
More details below:
https://github.com/facebook/create-react-app/issues/2526#issuecomment-308081573
Upvotes: 2
Reputation: 612
I also had this issue and fixed it by installing react, react-dom and react-test-renderer of the same version.
Some background:
So try making react-test-renderer the same version as your react and react-dom.
Upvotes: 7
Reputation: 6949
For the benefit of others who have the same problem: it was fixed when I cleaned up my global node_modules
and left react
, react-native
, and some other stuff only in the project's node_modules
.
Upvotes: 2