我四处寻找这个问题的解决方案。他们都建议添加"jsx": "react"
到您的 tsconfig.json 文件。我已经做到了。另一种是添加"include: []"
,我也做过。但是,当我尝试编辑时仍然收到错误.tsx
文件。下面是我的 tsconfig 文件。
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"allowJs": true,
"checkJs": false,
"jsx": "react",
"outDir": "./build",
"rootDir": "./lib",
"removeComments": true,
"noEmit": true,
"pretty": true,
"skipLibCheck": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": [
"./lib/**/*"
],
"exclude": [
"node_modules"
]
}
任何的意见都将会有帮助。我正在使用 babel 7 使用 env、react 和 typescript 预设来编译所有代码。如果你们需要更多文件来帮助调试,请告诉我。
每次我跑步npm start
,它会覆盖我配置的任何内容{jsx: ...}
with react-jsx
为了兼容 React 17 中的 JSX 转换。
The following changes are being made to your tsconfig.json file:
- compilerOptions.jsx must be react-jsx (to support the new JSX transform in React 17)
问题是 VSCode 使用旧版本的 typescript (4.0.3),而项目附带的 typescript 版本是 (4.1.2)。
以下对我来说是成功的:
- Go to the command palette CTRL+Shift+P (Or ⌘+Shift+P on Mac).
- 选择“TypeScript:选择 TypeScript 版本...”。
- 选择“使用工作区版本”。
PS:除非您使用任何 .tsx 文件,否则此选项不会显示(感谢 @awran5 的评论和良好的收获)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)