-
Notifications
You must be signed in to change notification settings - Fork 24.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESLint does not find React Native components #28549
Comments
|
Hi @tapz, many factors can be the the root cause of this. eslint version, VS Code plugins, etc.. could you provide a very simple reproducible repo that we can check out? My hunch is that it is an environment issue rather than an issue with React Native. |
@safaiyeh It cannot be VS code plugin as I run eslint from the command line. Eslint version you can find from the package.json above. |
My .eslintrc:
|
same problem here: here's my eslintrc.js
|
As a temporary workaround until this gets resolved: module.exports = {
settings: {
'import/ignore': ['react-native'],
}
} |
Thanks @jchook, this really helped! |
* chore: fix security alerts rm -f yarn.lock && yarn * chore(lint): dangling comma in JSON file * chore(lint): workaround react-native import/export issue Required by facebook/react-native#28549 * chore(types): new flow-bin pointed out usage did not match types usage is how it was actually working, types should conform to usage * chore(whitespace): commit results of new prettier major version they have changed some of their defaults * chore: `yarn upgrade --latest` except flow-bin pinned to match react-native
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:
|
Any reason why the import/export is done this way? |
Note: this actually ignores any packages with {
"settings": {
"import/ignore": [
"node_modules/react-native/index\\.js$"
]
}
} |
We experienced this when upgrading from 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 We're using the workaround posted by @benadamstyles to get around this issue. |
I have a newly initialized app, still a problem as of the moment. It says:
|
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions. |
Bumping thread to remove stale label (still an issue). |
still an issue on rn 0.63.4 from 0.61.5 |
I also hit this issue trying to import react-native into a Gatsby component.
Downgrading to 6.14.10 per the gatsby-plugin-react-native-web using the expo archive resolved it for me:
|
So is the fix here in RN's court, or ESLint's, or ... ? |
AFAIK the issue is caused by React Native using dynamic imports. Static analysis tools like ESLint do not support that. |
So perhaps the fix is in the react-native community eslint rules ? Or similar? https://github.com/facebook/react-native/blob/main/packages/eslint-config-react-native-community/index.js |
* chore: fix security alerts rm -f yarn.lock && yarn * chore(lint): dangling comma in JSON file * chore(lint): workaround react-native import/export issue Required by facebook/react-native#28549 * chore(types): new flow-bin pointed out usage did not match types usage is how it was actually working, types should conform to usage * chore(whitespace): commit results of new prettier major version they have changed some of their defaults * chore: `yarn upgrade --latest` except flow-bin pinned to match react-native
This disables my other eslint warnings i.e. no-unused-vars or no-console stop working.. |
is this still being worked on? |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Any update? |
any update? |
1 similar comment
any update? |
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?
React Native version:
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
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
The text was updated successfully, but these errors were encountered: