我最近尝试检查我的 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/