Even tho module is installed and it exists, Flow cannot resolve it and throws error.
See below:
1) Inside bash I ran flow
and it throws error that module is not found
user@pc:~/code/project$ flow
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/functionalities/Growth/index.js:3:25
Cannot resolve module react-redux.
1│ // @flow
2│ import React from "react"
3│ import { connect } from "react-redux"
4│
5│ type Props = {
6│ children: Function
Found 1 error
2) Below command checks whether directory exists and it does
user@pc:~/code/project$ ls node_modules | grep react-redux
react-redux
I tried to remove and reinstall both node_modules
directory and yarn.lock
file.
Versions should be matching:
flow version
Flow, a static type checker for JavaScript, version 0.77.0
.flowconfig:
[version]
0.77.0
This is very likely bug with Flow, I also submitted issue.
You have two options:
flow-typed
to find the dependency type
file/stub it for youI use option 2 but it is nice to know what is happening underneath
In .flowconfig
, add a directory under [libs]
,
...
[libs]
/type-def-libs
...
Now, create that directory at your project root and a file /type-def-libs/react-redux
which contains,
declare module 'react-redux' {
declare module.exports: any;
}
flow-typed
, if using yarn yarn add -D flow-typed
yarn flow-typed install
Flow is looking for the type definition for the module you are importing. So while the module does exist in /node_modules
that module doesn't have a type definition file checked into its code.
I had the same issue as you.
I resolved it by using flow-typed
I did the following:
flow-typed
globally. example: $ npm install -g flow-typed
$ flow-typed install [email protected]
• Searching for 1 libdefs...
• flow-typed cache not found, fetching from GitHub...
• Installing 1 libDefs...
• react-redux_v5.x.x.js
└> ./flow-typed/npm/react-redux_v5.x.x.js
react-redux
You should see this if the install was successful.$ npm run flow
in your project. The error with react-redux
will no longer be there.Check your .flowconfig
and remove <PROJECT_ROOT>/node_modules/.*
under the field [ignore]
(in case you have it there).
UPDATE 1 (by arka):
Or you can add !<PROJECT_ROOT>/node_modules/react-redux/.*
after <PROJECT_ROOT>/node_modules/.*
. This will ignore all the modules except for react-redux
.
Thanks to @meloseven who solved it here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With