Flow: Error: Cannot resolve module react-native

Created on 26 Oct 2018  Â·  4Comments  Â·  Source: facebook/flow

When running flow I get the following error:

Error ┈┈ index.js:3:29

Cannot resolve module react-native.

     1│ /* @flow */
     2│
     3│ import { AppRegistry } from 'react-native';
     4│ import App from './src/App';
     5│
     6│ AppRegistry.registerComponent('myApp', () => App);

Found 1 error

Now, I don't care about checking that my code is calling in to libraries (like react-native) with the correctly annotated Flow types. So I don't need to import type libs for these external libraries. I simply want to get rid of this error, and just have Flow check my own code files for type errors (at least for now).

Is there a config option I can use to ignore these types of errors (which are not code errors)?

Most helpful comment

Add something like this to your .flowconfig:

[options]
module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/src/react-native-dummy.js'

Contents of src/react-native-dummy.js:

declare export default {NativeModules: Object};

That was all that I needed, if there are other symbols that you need just add them to the dummy file (AppRegistry I guess).

Relevant Flow config documentation: https://flow.org/en/docs/config/options/#toc-module-name-mapper-regex-string

All 4 comments

Add something like this to your .flowconfig:

[options]
module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/src/react-native-dummy.js'

Contents of src/react-native-dummy.js:

declare export default {NativeModules: Object};

That was all that I needed, if there are other symbols that you need just add them to the dummy file (AppRegistry I guess).

Relevant Flow config documentation: https://flow.org/en/docs/config/options/#toc-module-name-mapper-regex-string

@lll000111 that worked perfectly. thanks!

This is the only option that has worked for me.

declare export default {NativeModules: Object};

Perfect!

Was this page helpful?
0 / 5 - 0 ratings