Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native: 'require' is not defined

I'm using clean project and I cannot use require in any part of my code, for example here in the Image:

<Image
  style={styles.stretch}
  source={require('./img/favicon.png')}
/>

or in any other part like here using the react-native-router-flux plugin, I want to overwrite the back button image but I cannot change it because 'require' is not defined.

<Scene backButtonImage={require('./custom_icon.png')} />

This is my package.json

  {
  "name": "CleanProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "15.4.2",
    "react-native": "0.40.0",
    "react-native-router-flux": "^3.37.0"
  },
  "devDependencies": {
    "babel-eslint": "^7.1.1",
    "babel-jest": "18.0.0",
    "babel-preset-react-native": "1.9.1",
    "eslint": "^3.12.0",
    "eslint-plugin-react": "^6.8.0",
    "jest": "18.1.0",
    "react-test-renderer": "~15.4.0-rc.4"
  },
  "jest": {
    "preset": "react-native"
  }
}    

Do you have any idea?

like image 504
SoldierCorp Avatar asked Jan 17 '17 19:01

SoldierCorp


1 Answers

It's probably just a config issue with your Linter. It should build just fine. If you want to remove the error in your developer tool and are using ESLint, at the top of your file try adding:

/* global require */
like image 145
antoinem Avatar answered Nov 15 '22 09:11

antoinem