Jar*_*vis 5 javascript reactjs flowtype react-native flow-typed
我正在使用Flow:用于响应前端应用程序的静态类型检查库,对于从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
Run Code Online (Sandbox Code Playgroud)
编辑: 安装流类型后,我的.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]
Run Code Online (Sandbox Code Playgroud)
如何在.flowconfig文件中映射此类导入的流?
提前致谢。
成功了。
相对路径实际上不适用于 Flow。
我们需要映射从项目根目录的导入以便 Flow 能够理解。
我将导入更改为
import words from 'def/words';
Run Code Online (Sandbox Code Playgroud)
将以下内容添加到您的 .flowconfig 文件中
module.name_mapper='^def\(.*\)$' -> '<PROJECT_ROOT>/src/abc/def/\1'
Run Code Online (Sandbox Code Playgroud)
修复以上错误。
| 归档时间: |
|
| 查看次数: |
1592 次 |
| 最近记录: |