'Cannot find module 'babel-preset-react'

This is my first React Native project. The repo is here.

When I start up expo, I get the error:

Cannot find module 'babel-preset-react'

Among others, it has these dependencies:

"expo": "^32.0.0",
"react": "16.8.4",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.1.tar.gz",
"@babel/core": "7.3.4",
"babel-core": "^7.0.0-bridge.0",
"@babel/preset-react": "^7.0.0",

I found these four libraries in my app's /node_modules that each contain a dev dependency on "babel-preset-react":

hoist-non-react-statics, prop-types, react-input-autosize and react-proxy.

None of these have newer versions that depend on "@babel/preset-react".



Solution 1:[1]

I had this a few, every time I install a new module/plugin. My solution has been to delete node_modules folder and yarn install or npm install.

It stops the error. I'm not sure is the right solution (would be interested to know if it is), but works.

Solution 2:[2]

Worked for me, I had to change ['react'] to ['@babel/preset-react'] in .bablerc when upgrading from babel 6.x to 7.x - thanks!

enter image description here

Solution 3:[3]

This seems to be an issue to do with an expo project being in a bad state.

Expo is an express set of libs with the goal of simplifying development, but it is not compatible with most react native examples in the wild.

After further review, it looks like you may have followed a regular react native example in an Expo based project, without first ejecting.

Solution 4:[4]

I had a similar issue wherein I mistyped babel/preset-react as babel-preset-react in the babel config file.

Correcting the typo helped me resolve the issue.

Solution 5:[5]

I had this issue after an upgrade. I needed a restart and it was solved. Apparently some caching issue or running process which still uses an old dependency.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luiz Henrique Pinto
Solution 2 ashish siddhu
Solution 3
Solution 4 Kumar Gaurav
Solution 5 FrankyHollywood