Dan Cancro
Dan Cancro

Reputation: 1461

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".

Upvotes: 18

Views: 36962

Answers (6)

ashish siddhu
ashish siddhu

Reputation: 219

I had to change ['react'] to ['@babel/preset-react'] in .bablerc when upgrading from babel 6.x to 7.x:

{
    "presets": [
        "@babel/preset-env",
        "@babel/preset-react",
    ]
}

Upvotes: 7

Hritik Bakshi
Hritik Bakshi

Reputation: 121

First of all make sure the babel config has '@babel/preset-react' in presets and not 'babel-preset-react'

Apart from that. this did it for me:

npm i @babel/preset-react 

npm i @babel/core

Upvotes: 7

FrankyHollywood
FrankyHollywood

Reputation: 1773

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.

Upvotes: 0

Kumar Gaurav
Kumar Gaurav

Reputation: 173

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.

Upvotes: 1

Luiz Henrique Pinto
Luiz Henrique Pinto

Reputation: 59

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.

Upvotes: 5

Steven Stark
Steven Stark

Reputation: 1259

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.

Upvotes: 2

Related Questions