JSX का उपयोग तब तक नहीं किया जा सकता जब तक कि "- jsx" झंडा "jsx" "रिएक्शन-jsx" नहीं दिया जाता

Nov 23 2020

टाइपस्क्रिप्ट फेंकता है:

JSX का उपयोग नहीं कर सकते जब तक कि '--jsx' ध्वज प्रदान नहीं किया जाता है। (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" या विंडो के नीचे दाईं ओर टाइपस्क्रिप्ट संस्करण पर क्लिक करें। टाइपस्क्रिप्ट: टाइप टाइपस्क्रिप्ट संस्करण का उपयोग करें कार्यक्षेत्र संस्करण ... 4.1.2 "

GabrielPetersson Dec 10 2020 at 15:10

यह एक नए बग के कारण है, यह vscode और टाइपस्क्रिप्ट के बीच एक बेमेल है। यदि अन्य समाधान काम नहीं करेंगे; मैं include: "src"अंदर बदल tsconfig.jsonगया

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