"jsx"가 "react-jsx"일 때 '--jsx'플래그가 제공되지 않으면 JSX를 사용할 수 없습니다.

Nov 23 2020

typescript는 다음을 던집니다.

'--jsx'플래그가 제공되지 않으면 JSX를 사용할 수 없습니다 .ts (17004)

로 변경 tsconfig.json jsx하면 react-jsxjsx가 작동합니다. 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 버전 선택 Workspace 버전 사용 ... 4.1.2 "

GabrielPetersson Dec 10 2020 at 15:10

이것은 새로운 버그로 인한 것이며 vscode와 typescript 사이의 불일치입니다. 다른 솔루션이 작동하지 않으면; 나는 변경 include: "src"내부 tsconfig.json

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