12

The app installs and opens but right when it opens this red screen appears with the below error message.

TBH I am not quite sure what I am doing and I really need some help. I was able to get my other project to work but when I started my second project this came up when trying to run the code. The code is just the basic code you get when you run: react-native init projectName

Error when trying to setup project in react-native.

Jonathan Ishii
  • 379
  • 2
  • 4
  • 12

12 Answers12

7

Change the version of "babel-preset-react-native" to "4.0.0". For the lastest version 5.0.0, the issue arises.

  1. Run npm install after the version change. Then start the emulator.
  2. Even then if you face issue, delete your node_modules directory, repeat step 1.
  3. Restart your machine if you see the issue again even after all tries.

Check github issue

pritam
  • 2,452
  • 1
  • 21
  • 31
4

I got the above mentioned error just now. I am using React Native v0.57 and my json file had this

 {
  "name": "AwesomeProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.5.0",
    "react-native": "0.57.1"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.45.6",
    "react-test-renderer": "16.5.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

I added "babel-preset-react-native": "4.0.0", and removed "metro-react-native-babel-preset": "0.45.6" in the "devDependencies" and the error was resolved.

  • I am using react native 0.51.1, and facing the same issue like you. I have changed the package.json file as you described. And run npm install again. But still getting an error while running it. Please help me out – Vivek Shah Sep 28 '18 at 13:28
1

Jonathan's solution worked for me as well:

Fixed. babel pushed an update that pushed to 5.0.0. set your presets to 4.0.0 and it will fix it.

https://github.com/facebook/react-native/issues/18962

1

I have upgraded to

"react-native": 0.57.7

"metro-react-native-babel-preset": "0.48.5",

Now the bundle is loading as expected.

1

My current version:

"react-native": "0.57.8",
"metro-react-native-babel-preset": "0.51.1",

Here how I fixed:

  1. add

    "devDependencies": {
      "babel-preset-react-native": "4.0.0"
    },
    
  2. remove node_modules

  3. npm install

Voilà! It works!

Saviah Kao
  • 320
  • 1
  • 5
  • 13
0

Fixed. babel pushed an update that pushed to 5.0.0. set your presets to 4.0.0 and it will fix it.

https://github.com/facebook/react-native/issues/18962

Jonathan Ishii
  • 379
  • 2
  • 4
  • 12
0

^^ what they said... change your "babel-preset-react-native" to 4.0.0 .

AJ Genung
  • 341
  • 1
  • 8
0

Try this command react-native upgrade

Hoque MD Zahidul
  • 10,560
  • 2
  • 37
  • 40
0

Had the same issue. Downgrading to "babel-preset-react-native": "4.0.0", did not work. running this worked for me

npm add @babel/runtime

M Sohaib Khan
  • 128
  • 2
  • 10
0

Try the followings: clean the build folder and try again.

run react-native start --reset-cache in one tab

and then run react-native in another tab

PRao
  • 1,439
  • 1
  • 8
  • 2
0

For me this answer worked:

https://stackoverflow.com/a/40966360/4483716

Basically I needed to give permission to folder

/Users/[username]/Library/LaunchAgents.

Use this command:

$ sudo chown $(whoami) /Users/$(whoami)/Library/LaunchAgents
Dasoga
  • 5,489
  • 4
  • 33
  • 40
0
  1. Add babel-preset-react-native version 4.0.0 to your devDependencies in package.json

"devDependencies": { "babel-preset-react-native": "4.0.0" },

  1. npm install
  2. react-native run-ios or android

If it still doesn't work try rm -rf node_modules/ and redo step 2 & 3

nullify0844
  • 4,641
  • 1
  • 22
  • 16