【发布时间】:2021-02-22 10:18:38
【问题描述】:
我正在使用 Expo 开发一个 React Native 应用程序,并且我正在使用来自 3rd 方的一些模板组件。 在我的 src 目录中,我有一个“app”文件夹,其中包含要使用的组件。 This is the app folder structure
And this is the whole folder structure
几乎每个组件也是这样构造的: Example of Button component
我的 tsconfig.json 文件给我带来了问题,因为我还需要更改一些路径:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"jsx": "react-native",
"lib": ["dom", "esnext"],
"moduleResolution": "node",
"noEmit": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"strict": true,
"noImplicitAny": false,
"baseUrl": "./",
"paths": {
"components/*": ["./app/components"],
"components/*/*": ["./app/components/*/index"],
"services/*": ["./app/services"],
"app/*": ["./app"],
"navigation/*": ["./app/navigation"],
"theme/*": ["./app/theme/*"]
}
}
}
它正在抱怨这一点
Pattern 'components/*/*' can have at most one '*' character.
当我尝试将 Button 组件导入到我的页面 Register.tsx 中时,这就是 React native 所抱怨的:
Unable to resolve "components/atoms/text" from "app/components/atoms/button/index.js"
我正在尝试所有解决方案来解决此问题,但它不起作用。我尝试手动更改每个导入,但这不是一个可行的选项,非常耗时且没有任何意义。
有解决此问题的建议吗?
【问题讨论】:
标签: typescript react-native import