facebook / facebook/flow

Correctly resolve a `node_module` inside .flowconfig

Open
#3,893 2 comments 8 reactions 0 assignees View on GitHub
module resolution
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I have webpack aliases set up in my webpack config:

```
resolve: {
extensions: ['.js', '.jsx'],
alias: {
components: path.resolve(__dirname, 'src/components/'),
styles: path.resolve(__dirname, 'src/components/styles/'),
utils: path.resolve(__dirname, 'src/utils/')
}
```

I also have [options] set up in my .flowconfig to account for this (so that I don't get Required module not found errors everywhere):

```
[ignore]
.*/node_modules/.*

[include]

[libs]
./libdefs.js

[options]
esproposal.class_static_fields=enable
esproposal.class_instance_fields=enable
esproposal.decorators=ignore
module.name_mapper='^components\(\/?.*\)$' -> '/src/components/\1'
module.name_mapper='^styles\(\/?.*\)$' -> '/src/components/styles/\1'
module.name_mapper='^utils\(\/?.*\)$' -> '/src/utils/\1'
```

I get no flow errors for standard imports from node_modules, like import moment from 'moment'. However, when I try and import from within a node_module like so:

```
import _uniqueId from 'lodash/uniqueId'
import classNames from 'classnames/bind'
```

I get the old error:

```
yarn run v0.20.3
$ "/Users/rorysmith/code/gen/node_modules/.bin/flow"
src/components/Calendar.jsx:4
4: import _times from 'lodash/times'
^^^^^^^^^^^^^^ lodash/times. Required module not found

src/components/Calendar.jsx:5
5: import _uniqueId from 'lodash/uniqueId'
^^^^^^^^^^^^^^^^^ lodash/uniqueId. Required module not found

src/components/Calendar.jsx:7
7: import classNames from 'classnames/bind'
^^^^^^^^^^^^^^^^^ classnames/bind. Required module not found

src/components/Category.jsx:16
16: import _uniqueId from 'lodash/uniqueId'
^^^^^^^^^^^^^^^^^ lodash/uniqueId. Required module not found
```

How can I resolve this so that the error doesn't show?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.