. Advertisement .
..3..
. Advertisement .
..4..
I am working with javascript and getting the error message:
Cannot use JSX unless the '--jsx' flag is provided
Here is the detail of the code that I ran:
{
"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"
]
}
I need an explanation for the problems I’ve encountered. How to fix Cannot use jsx unless the ‘–jsx’ flag is provided?
The cause: The error “Cannot use jsx unless the ‘–jsx’ flag is provided” appears because it needs to secure the request the IDE and your project uses are using the same version of TypeScrip. Its’ versions should match.
Solution: Restart your IDE because
tsconfig.json
changes aren’t always taken up right away.The other way: Replace
react-jsx
withreact
in thetsconfig.json
file:npm start
overrides everything I have in{jsx: ...}
andreact-jsx
to make it compatible with React’s JSX transformation.The problem is that VSCode uses an older version (4.0.3), but the version included with the project is (4.1.2).
These were the steps that worked for me:
CTRL
+
Shift
+
P
(Or
+
Shift
+
P
On Mac