除非在“ jsx”为“ react-jsx”时提供“ --jsx”标志,否则无法使用JSX

费哈

打字稿抛出:

除非提供了'--jsx'标志,否则无法使用JSX.ts(17004)

更改tsconfig.json jsx为后react-jsx,jsx可以使用。再次yarn start将tsconfig.json更改为react-jsx

react-scripts 已更新至4.0.1。

package.json

"dependencies": {
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.1",
    "semantic-ui-css": "^2.4.1",
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.2.2",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^14.14.9",
    "@types/react": "^17.0.0",
    "@types/react-dom": "^17.0.0",
    "@typescript-eslint/eslint-plugin": "^4.8.1",
    "@typescript-eslint/parser": "^4.8.1",
    "eslint-config-react": "^1.1.7",
    "eslint-plugin-react": "^7.21.5",
    "eslint-plugin-react-hooks": "^4.2.0",
    "typescript": "^4.1.2"
  },

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

如何解决这个问题?

费哈

您可以通过以下方式解决此问题

“ Ctrl + Shift + P”或单击窗口右下方的Typescript版本。TypeScript:选择TypeScript版本Use Workspace Version ... 4.1.2“

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Create React App显示“除非提供'--jsx'标志,否则无法使用JSX”

在VS Code中打开JSDoc会产生“除非提供'--jsx'标志,否则无法使用JSX”

出现错误TS17004:除非提供'--jsx'标志,否则无法使用JSX

编织时,除非在RStudio中运行,否则网状无法访问Python中的R变量

除非在 React 中刷新页面,否则按钮的事件侦听器不起作用

使用Typescript时无法从单独的文件导入React JSX

除非在引号内,否则将其分解为单词的Python正则表达式

Nginx使用react-router 4忽略/ api location指令,除非在Firefox专用浏览中

TypeScript 和 React/JSX:为反应组件的超类提供道具时出现 tsc 编译器错误

除非在程序启动时按住按钮,否则XINPUT_GAMEPAD_A将不起作用

如果条件为假,如何使用React返回空的jsx?

默认的获取方法不会返回值,除非在Sequelize中使用TypeScript时使用了`getDataValue()`。

在React JSX中使用if语句

使用Jsx而不导入react

使用 JSX 的 React 替代方案

除非在引号中,否则如何匹配注释?

使用JSX react / react-in-jsx-scope时,“反应”必须在范围内?

除非在c:驱动器上,否则无法从cmd访问Python

除非在调试模式下刷新 Cordova iOS 项目,否则无法正确加载源

除非在一个网络上,否则无法更新

除非在JWT中如何使用通配符?

React JSX 中的 FontAwesome

什么是React JSX中的<>?

React Unterminated JSX内容

React JSX编辑风格

React JSX Transform无效

在React JSX中引用`this`

React JSX let语法?

在React JSX内部循环