标签: babel-plugin-module-resolver

React Native Typescript路径别名无法解析模块

所以基本上,我使用 RN 主页中的命令行创建了 React Native with Typescript:\nnpx react-native init MyApp --template react-native-template-typescript

\n

之后,我运行该项目并成功构建。\n但是,当我添加路径别名来导入我的文件时,它引发了错误:Unable to resolve module #folder/file from ... could not be found within the project or in these directories: node_modules

\n

我已经在 Google 上遵循了一些教程和错误解决方案,但我没有遇到任何运气。

\n

这是我的.babelrc文件(我尝试将文件从 babel.config.js 更改为 .babelrc 正如某些解析器所说,但它仍然不起作用)

\n
{\n  "presets": ["module:metro-react-native-babel-preset"],\n  "plugins": [\n    [\n      "module-resolver",\n      {\n        "root": ["./src"],\n        "extensions": [\n          ".js",\n          ".jsx",\n          ".ts",\n          ".tsx",\n          ".android.js",\n          ".android.tsx",\n          ".ios.js",\n          ".ios.tsx"\n        ],\n        "alias": {\n          "#src/*": [\n            "./src/*"\n          ],\n          "#configs/*": …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs react-native babel-plugin-module-resolver

19
推荐指数
2
解决办法
2万
查看次数