facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.09k stars 1.86k forks source link

react-native: Required module not found #3875

Open kimjuny opened 7 years ago

kimjuny commented 7 years ago

.flowconfig

...
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/
...

index.js

import { View } from 'react-native'; ---> produce: react-native. Required module not found.
...

Maybe my libs settings for flowconfig is broken?

  • react-native 0.42.3
  • flow-bin 0.45.0
kimjuny commented 7 years ago

Well, I managed to declare a 'react-native' module definition(libdef), this is a workaround, I prefer a general solution(if there is any?).

vTrip commented 7 years ago

Could you share you solution, I am getting this for all my modules that i import into files.

jukben commented 7 years ago

@vTrip For example:

Extend flowconfig like this

.flowconfig module.name_mapper='\(react-native\)' -> '<PROJECT_ROOT>/modulesStub.js'

and then create stub like this:

modulesStub.js export default {};

imerkle commented 7 years ago

This should work

[ignore]
<PROJECT_ROOT>/node_modules/[^r].* 

to generate custom regex goto https://dsslimshaddy.github.io/flowignore/

spinningarrow commented 7 years ago

Seeing this issue with flow 0.53.1 as well. Any idea what's causing it?

dozoisch commented 7 years ago

Getting the same with flow 0.53.1 and react-native August.

I have unsafe.enable_getters_and_setters=true. Is there any thing in terms of extension or anything that I need?

divyanshu013 commented 7 years ago

Here's a quick solution that works for me to ignore the flow related errors for react-native

  1. Change into your project directory
    cd my-awesome-project
  2. Create a directory called flow-typed in your project if it doesn't exists
    mkdir flow-typed
  3. Add a file react-native.js
    touch react-native.js
  4. Add the following to react-native.js and hit save using your favorite editor
    declare module 'react-native' {
    declare module.exports: any;
    }
bodolsog commented 6 years ago

@divyanshu013 You forgot mention that there is needed also:

  1. Add /flow-typed/ into .flowconfig as included libs:
    
    ;.flowconfig file

[include]

[libs] ; Your other libs, usually followed: ; node_modules/react-native/Libraries/react-native/react-native-interface.js ; node_modules/react-native/flow/ ; node_modules/expo/flow/ flow-typed/



After that flow will known, that should check flow-typed declarations for all "missed" libs
divyanshu013 commented 6 years ago

Actually the above solution worked for me at the point of writing. I haven't used flow since then so a lot might have changed. Thanks for updating

zhiquan-yu commented 6 years ago

@divyanshu013 I think it's a good solution, maybe react-native team can give us a library defination in https://github.com/flowtype/flow-typed

MutableLoss commented 6 years ago

Probably quite obvious by now, but still an issue with v0.63.0 using React-Native 0.53.0's .flowconfig.

saadq commented 6 years ago

It looks like someone wrote up a Flow libdef for react-native as a GitHub gist. It looks like this would be a good place to start for submitting it to flow-typed.

Note – Based on the comments in that gist, there do seem to be some minor errors with that libdef that need to be fixed though.