我正在使用 Flow: Static type checking library对于 React 前端应用程序,它会为从 src 目录的内部导入抛出“无法解析”:
Example in file at path: src/abc/def/ghi/hello.jsx, I am using the following import:
import words from '../words';
--> Throws error "Cannot resolve module ../words
words.js is in src/abc/def dir
已编辑: 安装 flow-typed 后,我的 .flowconfig 看起来像这样:
[ignore]
.*/node_modules/.*
.*/build/.*
.*/dist/.*
[include]
.*/src/.*
.*/test/.*
[libs]
flow-typed
[lints]
[options]
all=true
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=src
[strict]
如何在 .flowconfig 文件中为此类导入映射流程?
提前致谢。
最佳答案
成功了。
相对路径并不真正适用于 Flow。
我们需要从项目根映射导入以便 Flow 理解。
我将导入更改为
import words from 'def/words';
将以下内容添加到您的 .flowconfig 文件
module.name_mapper='^def\(.*\)$' -> '<PROJECT_ROOT>/src/abc/def/\1'
修复了上述错误。
关于javascript - react : Flow: Import a local js file - cannot resolve issue module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52599780/