Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native cannot read property 'bindings' of null

Tags:

react-native

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?

like image 526
管原秀太 Avatar asked Jul 07 '18 04:07

管原秀太


2 Answers

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

like image 114
Laurie Williams Avatar answered Oct 06 '22 12:10

Laurie Williams


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

like image 15
Ronan Boiteau Avatar answered Oct 06 '22 13:10

Ronan Boiteau