我正在设置一个新的 react-native 项目,并希望通过将 jsconfig.json 文件添加到我的项目的根目录来配置应用程序以支持使用绝对路径导入模块。但该应用程序无法解析模块。我需要做一些额外的设置吗?
我已经创建了一个具有以下结构的 react-native-cli 2.0.1 的新 React-Native 项目,并尝试在 App.js 中导入 MyButton,如下所示:`import MyButton from '~/components/MyButton';``
|-- android
|-- ios
|-- node_modules
|-- src
|-- components
|-- MyButton.js
|-- App.js
|-- .eslintrc.js
|-- .flowconfig
|-- .watchmanconfig
|-- app.json
|-- babel.config.json
|-- index.js
|-- jsconfig.json
|-- metro.config.js
|-- package.json
Run Code Online (Sandbox Code Playgroud)
jsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
包.json
{
"name": "TestApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "react-native start",
"test": "jest",
"lint": "eslint ." …Run Code Online (Sandbox Code Playgroud)