我在webpack配置中设置了webpack aliases
:
resolve: {
extensions: ['.js', '.jsx'],
alias: {
components: path.resolve(__dirname, 'src/components/'),
styles: path.resolve(__dirname, 'src/components/styles/'),
utils: path.resolve(__dirname, 'src/utils/')
}
我还在[options]
设置了.flowconfig
来解释此问题(因此我无法在任何地方收到Required module not found
个错误):
[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\(\/?.*\)$' -> '<PROJECT_ROOT>/src/components/\1'
module.name_mapper='^styles\(\/?.*\)$' -> '<PROJECT_ROOT>/src/components/styles/\1'
module.name_mapper='^utils\(\/?.*\)$' -> '<PROJECT_ROOT>/src/utils/\1'
我从node_modules
获得标准导入的流量错误,例如import moment from 'moment'
。但是,当我尝试从node_module
内导入时,如此:
import _uniqueId from 'lodash/uniqueId'
import classNames from 'classnames/bind'
我得到了旧错误:
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
如何解决此问题,以便错误无法显示?