【问题标题】:Pattern 'components/*/*' can have at most one '*' character模式 'components/*/*' 最多可以有一个 '*' 字符
【发布时间】: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


    【解决方案1】:

    我真的不明白你要做什么。但是,如果您尝试从按钮文件夹中导入 index.js,那么您应该是这样的;

    import index.js from '../app/components/atoms/button
    

    【讨论】:

    • 问题出在 tsconfig 文件中。这一行 ``` "components/*/*": ["./app/components/*/index"], ``` 给了我这个错误:模式 'components/*/*' 最多可以有一个 ' *' 字符
    • 这个解决方案不适合我,因为我需要更改目录中每个文件的导入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    • 2011-07-18
    • 2014-03-23
    • 2010-11-13
    • 1970-01-01
    • 2021-10-11
    • 1970-01-01
    相关资源
    最近更新 更多