3

I have started a React Native project from scratch and configured Flow.

When I run npm run flow everything works fine except a small problem with the react-native module:

Cannot resolve module react-native.

I am using:

"react": "16.3.1",
"react-native": "0.55.3",
"flow-bin": "0.74.0"

My .flowconfig is:

[ignore]
.*/node_modules/.*
.*/.cache/.*
.*/test/.*

[include]

[libs]

[lints]

[options]

[strict]

Tried with "flow-typed": "2.4.0" but didn't work.

I found the following issue but there aren't any solutions :/

10
  • Did you used . create-react-app tool to create seeds and then after did npm i somepack? Commented Jun 8, 2018 at 15:31
  • I forgot to say that I am using Expo. Commented Jun 8, 2018 at 15:32
  • even you used Expo but did you follow above step? Commented Jun 8, 2018 at 15:33
  • No, that all. I am using the Flow extension for Visual Studio Code but I don't think this makes sense. Commented Jun 8, 2018 at 15:38
  • I initialized blank expo app, installed flow-bin, initialized empty .flowconfig file, added @flow to App.js and executed npx flow - everything seems to be working. Have I missed anything to reproduce your issue? Commented Jun 8, 2018 at 21:55

2 Answers 2

6

You need to add a type definition for react-native.

Create a folder called type-def-lib in your project root and inside create a file called react-native.js with these contents

declare module 'react-native' {
  declare module.exports: any
}

Then in your .flowconfig add that folder under libs:

[libs]
./type-def-libs

Now yarn run flow should produce no errors.

Sign up to request clarification or add additional context in comments.

2 Comments

What does this actually do? Thanks!
it provides a "libdef" for the react-native module, I am not sure why it works at all as libdefs are not necessary but you can read the documentation about the process here: flow.org/en/docs/libdefs as far as I know, flow does the exact process above automatically for all librarys that do not have type declarations (setting them to any) so I'm gonna assume that the current react native flow type declaration has some sort of bug and this explicit any declaration overrides that.
0

In the latest version flow-bin (0.157.0), this problem can be resolved by removing .*/node_modules/.* from [ignore]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.