Skip to content
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

"View not found in react-native" #1754

Open
jchook opened this issue May 10, 2020 · 1 comment
Open

"View not found in react-native" #1754

jchook opened this issue May 10, 2020 · 1 comment

Comments

@jchook
Copy link

jchook commented May 10, 2020

Some modules do not resolve with eslint-plugin-import that DO resolve in react-native.

See facebook/react-native#28549

I noticed that this also happens with react-native-screens.

Unable to resolve path to module 'react-native-screens'.

When I look at node_modules/react-native/index.js, I can see some pretty "non-standard" commonJS exports, which I suspect could contribute to the issue, but otherwise I don't see why it would fail on these modules in particular.

module.exports = {
  // Components
  get AccessibilityInfo(): AccessibilityInfo {
    return require('./Libraries/Components/AccessibilityInfo/AccessibilityInfo');
  },
  get ActivityIndicator(): ActivityIndicator {
    return require('./Libraries/Components/ActivityIndicator/ActivityIndicator');
  },
  get Button(): Button {
    return require('./Libraries/Components/Button');
  },
...

For react-native-screens, it appears to use the (rarely used?) files directive in package.json.

Code that produces the false positive linter error:

import { enableScreens } from 'react-native-screens' // error
import { View } from 'react-native' // error
@ljharb
Copy link
Member

ljharb commented May 11, 2020

Indeed, using a getter on module.exports is both slow and causes all sorts of subtle issues - and also makes any linter plugin unable to statically resolve imports.

I'd suggest filing issues on react-native to stop using dynamically loaded exports. I'm not sure how else any linter could support it (and notably, native ESM in node absolutely doesn't).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants