React native: "require" is undefined

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

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

or in any other part, such as here, using the action-native-router-flux plugin, I want to overwrite the inverse image of the button, 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 ideas?

+5
source share
1 answer

This is probably just a configuration problem with your Linter. It should be built just fine. If you want to remove the error in your developer tool and use ESLint, try adding at the top of the file:

 /* global require */ 
0
source

Source: https://habr.com/ru/post/1262951/


All Articles