Flow: Required module not found if I import from root.

Created on 27 Dec 2016  路  3Comments  路  Source: facebook/flow

I have following piece of code:

import {pickValues} from 'shared/helpers';
import {setCurrentExecutionChain} from 'actions/index';
import {setAnswer, getCompleteJson} from 'shared/solver';
import {showError} from 'shared/notification';
import {answers} from 'api/issueTasks';

I configure webpack by

  resolve: {
    root: path.resolve('./src'),
    extensions: ['', '.js', '.jsx', '.coffee', '.sass', '.less', '.scss']
  },

to resolve it from my root javascript folder: src
But flow still raise following errors:

src/containers/executions/Solve/Execution.js:8
  8: import {pickValues} from 'shared/helpers';
                              ^^^^^^^^^^^^^^^^ shared/helpers. Required module not found

src/containers/executions/Solve/Execution.js:9
  9: import {setCurrentExecutionChain} from 'actions/index';
                                            ^^^^^^^^^^^^^^^ actions/index. Required module not found

src/containers/executions/Solve/Execution.js:10
 10: import {setAnswer, getCompleteJson} from 'shared/solver';
                                              ^^^^^^^^^^^^^^^ shared/solver. Required module not found

src/containers/executions/Solve/Execution.js:11
 11: import {showError} from 'shared/notification';
                             ^^^^^^^^^^^^^^^^^^^^^ shared/notification. Required module not found

src/containers/executions/Solve/Execution.js:13
 13: import {answers} from 'api/issueTasks';
                           ^^^^^^^^^^^^^^^^ api/issueTasks. Required module not found

Even if I add ./src (which is relative to .flowconfig file) folder to my .flowconfig

[include]
./src

Most helpful comment

You should be able to add a module.name_mapper to your .flowconfig to get rid of the errors and tell flow about the alias:

[options]

module.name_mapper='^shared\(\/?.*\)$' -> '<PROJECT_ROOT>/src/shared/\1'

Docs: https://flowtype.org/docs/modules.html#aliasing-module-names

Generally, I repeat all of the module aliases in my webpack config in my flowconfig.

All 3 comments

You should be able to add a module.name_mapper to your .flowconfig to get rid of the errors and tell flow about the alias:

[options]

module.name_mapper='^shared\(\/?.*\)$' -> '<PROJECT_ROOT>/src/shared/\1'

Docs: https://flowtype.org/docs/modules.html#aliasing-module-names

Generally, I repeat all of the module aliases in my webpack config in my flowconfig.

But OP is not using an alias - he is simply using the root which is set by the webpack resolver to resolve to './src'

Flow has no relation to webpack so it doesn't care what webpack's resolver is set to.

Was this page helpful?
0 / 5 - 0 ratings