「jsx」が「react-jsx」の場合、「-jsx」フラグが指定されていない限り、JSXを使用できません。

Nov 23 2020

typescriptがスローします:

'--jsx'フラグが指定されていない限りJSXを使用できません。ts(17004)

に変更tsconfig.json jsxするとreact-jsx、jsxが機能します。yarn starttsconfig.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"
  ]
}

これを修正する方法は?

回答

7 FelHa Nov 30 2020 at 17:45

これは次の方法で修正できます。

「Ctrl + Shift + P」またはウィンドウの右下にあるTypescriptバージョンをクリックします。TypeScript:TypeScriptバージョンを選択ワークスペースバージョンを使用... 4.1.2 "

GabrielPetersson Dec 10 2020 at 15:10

これは新しいバグによるもので、vscodeとtypescriptの不一致です。他の解決策が機能しない場合; 私は変更include: "src"の内側tsconfig.json

"include": [
     "./src/**/*.ts"
]