react-native: ESLint does not find React Native components
Please provide all the information requested. Issues that do not follow this format are likely to stall.
Description
I’m getting these ESLint errors in all of my js files, which import React Native components. Imports from all other libraries work just fine and the app also compiles and runs without problems. Any idea what could be the reason?
3:3 error Text not found in 'react-native' import/named
4:3 error View not found in 'react-native' import/named
5:3 error ScrollView not found in 'react-native' import/named
6:3 error StyleSheet not found in 'react-native' import/named
import {
Text,
View,
ScrollView,
StyleSheet
} from 'react-native';
"react-native": "0.62.0",
"eslint": "6.8.0",
"eslint-plugin-react-native": "3.8.1",
"@react-native-community/eslint-config": "1.0.0",
"flow-bin": "0.121.0" (not using in my code)
React Native version:
System:
OS: macOS 10.15.3
CPU: (4) x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
Memory: 1.27 GB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.16.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 28, 29
Build Tools: 21.1.1, 21.1.2, 22.0.0, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.1, 25.0.0, 25.0.2, 25.0.3, 26.0.0, 26.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.2
Android NDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6241897
Xcode: 11.4/11E146 - /usr/bin/xcodebuild
Languages:
Python: 2.7.17 - /usr/local/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.62.1 => 0.62.1
npmGlobalPackages:
*react-native*: Not Found
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
- eslint
Expected Results
Describe what you expected to happen.
No errors.
Snack, code example, screenshot, or link to a repository:
https://stackoverflow.com/questions/60973737/eslint-does-not-find-react-native-components
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 36
- Comments: 25 (2 by maintainers)
Links to this issue
Commits related to this issue
- chore(lint): workaround react-native import/export issue Required by https://github.com/facebook/react-native/issues/28549 — committed to mikehardy/react-native-share by mikehardy 4 years ago
- fix: security alerts / package updates 20200505 (#773) * chore: fix security alerts rm -f yarn.lock && yarn * chore(lint): dangling comma in JSON file * chore(lint): workaround react-native ... — committed to react-native-share/react-native-share by mikehardy 4 years ago
- MOBILE: Ignore react-native imports https://github.com/facebook/react-native/issues/28549 — committed to the-seql/eslint-config by cvburgess 3 years ago
- fix: work around eslint import issue on windows see: https://github.com/facebook/react-native/issues/28549 — committed to byCedric/dogfood by byCedric 2 years ago
- fix: security alerts / package updates 20200505 (#773) * chore: fix security alerts rm -f yarn.lock && yarn * chore(lint): dangling comma in JSON file * chore(lint): workaround react-native ... — committed to mobiledev7/react-native-share by mobiledev7 4 years ago
Note: this actually ignores any packages with
react-nativein their name, e.g.react-native-svg, as it is parsed as a regex. Much safer to do:As a temporary workaround until this gets resolved:
still an issue on rn 0.63.4 from 0.61.5
I have a newly initialized app, still a problem as of the moment. It says:
Any update?
Any reason why the import/export is done this way?
We experienced this when upgrading from
v0.61.xtov0.63.0.We don’t have Flow enabled in our project. So in our case, I believe the error is caused by the addition of Flow typings in the updated entry point file. In
v0.61.x, the entry point file didn’t contain any Flow typings so the Babel parser could handle it.We’re using the workaround posted by @benadamstyles to get around this issue.
Looking at node_modules/react-native/index.js, you can see that it uses getters to define all the exports.
This interferes with the linter’s ability to statically resolve imports.
You can work around this issue by ignoring the entire react-native dependency in the eslint-plugin-import import/ignore setting:
via: https://stackoverflow.com/a/61734408
is this still being worked on?
My .eslintrc: