Hristo Eftimov
Hristo Eftimov

Reputation: 15703

React Flow: Cannot resolve module react-native

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 :/

Upvotes: 3

Views: 3570

Answers (2)

Fanchen Bao
Fanchen Bao

Reputation: 4279

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

Upvotes: 0

Robbie Milejczak
Robbie Milejczak

Reputation: 5770

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.

Upvotes: 6

Related Questions