我有一个现有的项目,我正在迁移到类型记录。这是我的文件结构:
my_app/
├─ app/
│ ├─ lib/
│ │ ├─ api/
│ │ │ ├─ index.ts
├─ config/
│ ├─ config.js
├─ .babelrc
├─ tsconfig.json在index.ts中,我正在进行以下导入:
import CONFIG from 'config/config';
在我安装打字本之前它还在工作。我安装了babel-plugin-module-resolver,我的.bablerc文件配置如下:
{
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
["module-resolver", {
"root": ["."]
}]
]
}当我安装类型记录时,我在index.ts中得到了这个错误:
Cannot find module config/config or its corresponding type declarations
我尝试将index.ts中的路径更改为此,然后错误就消失了,所以我知道这是路径别名问题:
import CONFIG from '../../../config/config'
在我的tsconfig.json中,我配置了如下路径:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"config/config": ["config/config"]
},
}
}我阅读了关于迁移到类型记录的Reactive原住民文档,阅读了大量关于这个主题的博客,并查看了类型记录文档和babel-plugin-module-resolver文档。我尝试过多种组合方式,包括使用*字符以及在这里和那里切换.和/。我觉得每一个例子都是不同的。
我的.bablerc当前如下所示:
{
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
["module-resolver", {
"root": ["."],
"alias": {
"config/config": "config/config"
}
}]
]
}有什么东西看上去像受过更多训练的眼睛吗?我提前非常感谢你!
发布于 2022-10-11 19:48:36
我从这个博客到底部找到了答案。非常简单,我只需关闭并重新启动vscode就可以检测到更改。谢什!
https://stackoverflow.com/questions/74022679
复制相似问题