node.js - “TouchableOpacity”不能用作 JSX 组件

标签 node.js react-native components

我最近尝试检查我的 React Native 项目。在进行 linting 时,我进行了一些安装和更改,但之后我的代码中出现了大量错误。在此之前我已经尝试过反转到分支,但它只是不断抛出相同的错误。

重要的是要注意这些错误发生在某些文件中而不是其他文件中。我在这里似乎找不到模式。

我已经尝试了此处找到的解决方案 ( NPM package cannot be used as a JSX Component - Type errors ) 但无济于事。这是我的一些文件的样子:

.eslint.js

module.exports = {
  root: true,
  extends: '@react-native-community',
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint'],
  overrides: [
    {
      files: ['*.ts', '*.tsx'],
      rules: {
        '@typescript-eslint/no-shadow': ['error'],
        'no-shadow': 'off',
        'no-undef': 'off',
        'no-console': 'warn',
      },
    },
  ],
};

tsconfig.js

{
  "compilerOptions": {
    "allowJs": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "jsx": "react-native",
    "lib": ["es2017"],
    "moduleResolution": "node",
    "noEmit": true,
    "strict": true,
    "target": "esnext"
  },
  "exclude": [
    "node_modules",
    "babel.config.js",
    "metro.config.js",
    "jest.config.js"
  ]
}

我还在我的 package.json 中添加了一个决议:

"resolutions": {
    "@types/react": "17.0.30",
    "@types/react-dom": "17.0.2"
},

最佳答案

将您的@types/react 更新到版本 17.0.43 并删除您的决议。

关于node.js - “TouchableOpacity”不能用作 JSX 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72757058/

相关文章:

mysql - SQL 结果长度且搜索时不显示任何内容

node.js - 是否可以获得存储在 Google Cloud Storage 上的图像的调整大小版本?

react-native - 包围 react-native-vector-icons

c# - 是否可以告诉 Visual Studio 不要将源文件视为 "component"?

javascript - Vuejs : Dynamic Recursive components

node.js - 如何在谷歌工作表中同步添加行?

javascript - 检查 writeFileSync 是否成功写入文件

node.js - Node.js 中的 AssertionError 定义在哪里?

iphone - React Native 博览会在没有 Mac 的情况下创建 iOS 应用程序?

vue.js - 如何使用 jest 测试 Vue.js 组件中方法的错误