管原秀太
管原秀太

Reputation: 261

react-native cannot read property 'bindings' of null

I tried to run a react-native simulator.

However, this error came out in the simulator:

Failed to load bundle(http://localhost:8081/index.bundle?
platform=ios&dev=true&minify=false) 
with error:(/Users/sugawarasyuta/Desktop/albums/index.js:
Cannot read property 'bindings' of null(null))

I double‐checked my code syntax. But I feel like this is not about that. Do you know how to solve this error?

Here are my files:

index.js

import React from 'react';
import { AppRegistry,View } from 'react-native';
import Header from './src/components/header';
import AlbumList from './src/components/AlbumList';


//Create a component
const App = () => (
<View>
<Header headerText= {'albums'} />
<AlbumList />
</View>
);

AppRegistry.registerComponent('albums', () => App );

AlbumList.js

import React,{Component}from 'react';
import {View, Text} from 'react-native';
import axios from 'axios';

class AlbumList extends Component {

componentWillMount(){
    axios.get('https://rallycoding.herokuapp.com/api/music_albums')
    .then(response => console.log(response));

}
render(){
return(
    <View>
        <Text>AlbumList!!!</Text>
    </View>
    );
}
}
export default AlbumList;

These are terminal statements:

/usr/bin/codesign --force --sign - --entitlements /Users/sugawarasyuta/Desktop/albums/ios/build/Build/Intermediates.noindex/albums.build/Debug-iphonesimulator/albums.build/albums.app.xcent --timestamp=none /Users/sugawarasyuta/Desktop/albums/ios/build/Build/Products/Debug-iphonesimulator/albums.app

/Users/sugawarasyuta/Desktop/albums/ios/build/Build/Products/Debug-iphonesimulator/albums.app: resource fork, Finder information, or similar detritus not allowed

Command /usr/bin/codesign failed with exit code 1



** BUILD FAILED **


The following build commands failed:

    CodeSign build/Build/Products/Debug-iphonesimulator/albums.app
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/albums.app
Launching org.reactjs.native.example.albums
org.reactjs.native.example.albums: 8385

This is my package.json. Are those dependencies correct?

{
"name": "albums",  
"version": "0.0.1",

"private": true,

"scripts": {
 "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },


  "dependencies": {

"axios": "^0.18.0",

"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",

"react": "16.3.1",

"react-native": "^0.56.0"

 },

"devDependencies": {

"@babel/preset-env": "^7.0.0-beta.53",

"babel-jest": "23.0.1",

"babel-preset-es2015": "^6.24.1",

 "babel-preset-react-native": "4.0.0",

"eslint-config-rallycoding": "^3.2.0",

 "jest": "23.1.0",

"react-test-renderer": "16.3.1"

},

"jest": {

 "preset": "react-native"

 }

}

I upgraded "babel-preset-react-native" from "4.0.0" to "^5.0.1" and another error came out:

error: bundling failed: SyntaxError: 
/Users/sugawarasyuta/Desktop/albums/index.js: Unexpected token (11:3)



  10 | const App = () => {

> 11 |    <Header headerText= {'albums'} />

     |    ^

  12 | 

  13 | };



at Parser.raise

(/Users/sugawarasyuta/Desktop/albums/node_modules
/@babel/core/node_modules/babylon/lib/index.js:776:15)

at Parser.unexpected    
(/Users/sugawarasyuta/Desktop/albums/node_modules/
@babel/core/node_modules/babylon/lib/index.js:2079:16)

at Parser.parseExprAtom (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:3157:20)

at Parser.parseExprSubscripts (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:2757:21)

at Parser.parseMaybeUnary (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:2736:21)

at Parser.parseExprOps (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:2643:21)

at Parser.parseMaybeConditional (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:2615:21)

at Parser.parseMaybeAssign (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:2562:21)

at Parser.parseExpression (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:2515:21)

at Parser.parseStatementContent (/Users/sugawarasyuta/Desktop/albums/node_modules/@babel/core/node_modules/babylon/lib/index.js:4076:21)
 BUNDLE  [ios, dev] ../../index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

I feel like this is not because of syntax error simply, but cause of dependencies. Do you know how can I fix it?

Upvotes: 25

Views: 22388

Answers (4)

batuhancam
batuhancam

Reputation: 1

FOR REACT-NATIVE VERSION 0.57 OR MORE

On babel.config.js, simply change presets as below

"presets": ["module:metro-react-native-babel-preset"]

This worked for me after trying many different solutions

Upvotes: 0

Ronan Boiteau
Ronan Boiteau

Reputation: 10138

For React Native 0.57

When upgrading to React Native 0.57, follow these steps to fix this issue:

  1. Upgrade the version of React in the package.json to 16.5

  2. Change the babel-preset dependency from "babel-preset-react-native": "^5" to "metro-react-native-babel-preset": "^0.45.0"

  3. Change the .babelrc configuration to:

    {
      "presets": ["module:metro-react-native-babel-preset"]
    }
    
  4. Run rm -rf node_modules/ to remove your old modules

  5. Run npm install to get a fresh node_modules/

  6. Run react-native upgrade to upgrade your config files

  7. Run rm -rf android/build/ ios/build/ to get rid of your old compiled apps

  8. Run your app again, it should work!

Source for the first steps

Upvotes: 16

RedEarth
RedEarth

Reputation: 147

REACT NATIVE 0.57 FRESH INSTALLS iOS ANDROID

I did a fresh install of react native from react-native init projectName

The package.json

{
  "name": "JesteeTestee",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
},
  "dependencies": {
    "react": "^16.5.2",
    "react-native": "0.57.4"
},
devDependencies": {
  "babel-jest": "23.6.0",
  "jest": "23.6.0",
  "metro-react-native-babel-preset": "^0.47.0",
  "react-test-renderer": "16.6.0-alpha.8af6728"
},
"jest": {
  "preset": "react-native",
  "transform": {
    "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
  }
}

}

As you can see it is the latest, current version of [email protected] and [email protected].

Also the default .babelrc

{
  "presets": ["module:metro-react-native-babel-preset"]
}

Simply added the following to the Jest part of the package.json;

"transform": {
  "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}

Given the hours I spent finding this today, if you are doing a fresh install and hit a snag just delete the project, start again and try this simple step only.

Tested for react-native run-ios and run-android.

Upvotes: 1

Laurie Williams
Laurie Williams

Reputation: 393

Without any further information, I suspect you need to update babel-preset-react-native.

When upgrading to 0.56, make sure to bump your babel-preset-react-native package.json dependency to ^5.0.1 or newer.

https://github.com/facebook/react-native/releases

Upvotes: 32

Related Questions