create-react-app: TypeError: Cannot assign to read only property 'jsx' of object '#
Describe the bug
When creating a react-typescript app using
npx create-react-app . --template typescript
The error:
yarn run v1.22.5
$ react-scripts start
/home/aditya/all/yt/twitter/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:239
appTsConfig.compilerOptions[option] = value;
^
TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'
at verifyTypeScriptSetup (/home/aditya/all/yt/twitter/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:239:43)
at Object.<anonymous> (/home/aditya/all/yt/twitter/node_modules/react-scripts/scripts/start.js:31:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 118
- Comments: 62 (2 by maintainers)
Commits related to this issue
- Some magic tweaks found from internet to fix a mysterious error https://github.com/facebook/create-react-app/issues/10110 — committed to Arch-vile/starck by deleted user 4 years ago
- Some magic tweaks found from internet to fix a mysterious error `github.com/facebook/create-react-app/issues/10110` — committed to Arch-vile/starck by deleted user 4 years ago
- Feat: Cleanup boilerplate code, install npm modules, fix create-react-app react-script@4.0.0 bug, create store and basic app layout Temp fixed create-react-app bug https://github.com/facebook/create-... — committed to convexhull/double-trouble-game by convexhull 4 years ago
- fix: create-react-app issue https://github.com/facebook/create-react-app/issues/10110 — committed to adizka/auto-test-app by adizka 4 years ago
- Fix eslint conflict rules and change TypeScript version to fix create-react-app issue: https://github.com/facebook/create-react-app/issues/10110 — committed to JulianPasquale/haptic-design-UI by JulianPasquale 4 years ago
- fix yarn start ができなくなったので修正 https://github.com/facebook/create-react-app/issues/10110 — committed to ura-kata/score-history by uttne 4 years ago
- Set fixed version of typescript, ref: https://github.com/facebook/create-react-app/issues/10110. — committed to rsksmart/rif-identity-manager by jessgusclark 4 years ago
- Set fixed version of typescript, ref: https://github.com/facebook/create-react-app/issues/10110. — committed to rsksmart/rif-identity-manager by jessgusclark 4 years ago
- fix: client.sh breaks with ts > 4.05 https://github.com/facebook/create-react-app/issues/10110 — committed to gvinokur/ch-react-workshop by gvinokur 4 years ago
- Fix CSS on Build (#18) * Use same version of SC as in rLogin. * ignore windows debug.log file. * revert jsx setting caused by build. * Set fixed version of typescript, ref: https://github.co... — committed to rsksmart/rif-identity-manager by jessgusclark 4 years ago
- Fixed an error starting the project The following occurred on `yarn start`: TypeError: Cannot assign to read only property 'jsx' of object '#<Object>' See: https://github.com/facebook/create-react-ap... — committed to ZeeCoder/frontier-test by ZeeCoder 4 years ago
- Temporary fix for TypeScript 4.1 and CRA See https://github.com/facebook/create-react-app/issues/10110 — committed to haggen/localthreat by haggen 3 years ago
- #fix TypeError TypeError: Cannot assign to read only property 'jsx' of object '#<Object>' https://github.com/facebook/create-react-app/issues/10110 — committed to born-kes/toolsGM by born-kes 3 years ago
- fix: dependency upgrade and declare explicit versions Ran into https://github.com/facebook/create-react-app/issues/10110 — committed to fredrikssongustav/gustavfredriksson by fredrikssongustav 3 years ago
- CD for main (#66) * Data vault view insert (#14) * Create authenticated component/container to hold the header and navigtation. - will handle navigation next. * Create navigation with useSta... — committed to rsksmart/rif-identity-manager by ilanolkies 3 years ago
- Downgraded Typescript Downgraded typescript due to an issue with Typescript 4.1+ being present with CRA 4.0 . For more information, check this page https://github.com/facebook/create-react-app/issues... — committed to SimonaCartuta/react-developer-assessment by SimonaCartuta 3 years ago
- bootsrap project, fix issue with current version of create react app typescript see: https://github.com/facebook/create-react-app/issues/10110 — committed to roadrunnersf/css-grid-calendar by roadrunnersf 4 years ago
Personally, I was able to fix this issue (this is on a fresh project) by: -changing the typescript version in package.json to “~4.0.5” -changing the value “jsx” in compilerOptions inside tsconfig.json to “react” instead of “react-jsx” -run
npm install
so that the older typescript version is installed -I don’t think this is needed but perhaps make sure vscode has the intellisense of ts set to the same or similar version to the one you’ve installed Mine is set to use the local one I just installed - 4.0.5 -I was then able to start the project normally withnpm start
I just deleted tsconfig.json and ran yarn start, and it recreates it and runs (I did update to ts 4.0.5 too). But you have to delete everytime you run yarn start. i.e
rm tsconfig.json && yarn start
Hacky until we get a fix.
I solve this issue
yarn start
Solution
Change typescript version in package.json
"typescript": "~4.0.5",
Change in tsconfig.json
"jsx": "react"
In the terminal
A quick solution as mentioned above 👍
+1 Me too.
I have this happening after upgrading to typescript 4.1
You can fix this issue for the time being by downgrading to Typescript 4.0.5. It is an issue with Typescript 4.1+ being present with CRA 4.0 and may be fixed once CRA 4.0.1 is released.
+1 Now i can’t create new typescript anymore !!!
Workaround for those who want to use TypeScript 4.1 and create-react-app 4.0.0: set the environment variable
DISABLE_NEW_JSX_TRANSFORM
totrue
to avoid the buggy code inverifyTypeScriptSetup.js
until 4.0.1 is released.Also,
"jsx"
must be set to"react"
intsconfig.json
The
scripts
section of mypackage.json
now looks like this:+1 seeing this as well
I’ve just had this exact error, the problem is in
create-react-app\packages\react-scripts\scripts\utils\verifyTypeScriptSetup.js
on Line 151 (to find it search forts.JsxEmit.ReactJ
) it was usingts.JsxEmit.ReactJsx
but should usets.JsxEmit.ReactJSX
(JSX being upper case)Thanks to @benneq this is fixed in the master branch (already three weeks ago), just needs a new patch version (see the fix: https://github.com/facebook/create-react-app/pull/9869). Can somebody release a 4.0.1?
please solve this . i have this error too.
Same issue I am facing. Just ran the
npx create-react-app my-app --template typescript
command. When I run it usingyarn start
, I get this error.I tried that. Downgraded to TS 4.0.5 and replace “react-jsx” with “react” in the tsconfig.json
jsx
field. But nothing seems to solve this.I solved this issue by upgrading
react-scripts
:++
You can add
DISABLE_NEW_JSX_TRANSFORM=true
to.env
file. This way it’ll stop replacingreact
withreact-jsx
For anyone also seeing this error… it is already known, and a fix has been merged to master.
What we are waiting for now is a React-Scripts v4.0.1 patch on npm… no word yet on when that’s happening.
The fix I am referencing: https://github.com/facebook/create-react-app/pull/9869
I just experienced the same issue
Modified start script in package.json to this and it works for now.
"start": "rm tsconfig.json && react-scripts start",
Have updated my initial post (see above)
Worked for me too - but when I run "npm run start"again, tsconfig.json keeps changing jsx from “react” to “react-jsx” which causes errors in my tsx files. Is there something else I need to change? Is this unrelated?
works for me with
react-jsx
intsconfig.json
, andand
in my
package.json
and off course installed the preset:npm i -D @babel/preset-react
as advised by the React team: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#removing-unused-react-importsI too : (
I solve this error updating react-scripts to 4.0.3
yarn upgrade react-scripts@4.0.3
Can anyone confirm if
4.0.1
resolves this issue? We did patch up some of the issues when modifying the tsconfig.@maltoze @madrus @gynekolog
Thanks! I changed the typescript version vs code was using and that seems to have resolved the issue. It’s still react-jsx, but now it works. Everything set to 4.1.x now.
Update the typescript version of your IDE.
I modified the jsx property in tsconfig.json to “react” instead of “react-jsx” and changed the typescript version in the package.json file. When i ran yarn install , it prompted me to select a typescript version, I chose 4.0.2 and now it runs without any errors!
This is not a solution in any kind of production environment that uses a VCS that ignores the node_modules directory.
You could also comment out the line 239 in verifyTypeScriptSetup.js if you do not want to remove your
Tsconfig file. To find this file. You must go to node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js
@Luan-Sens @ianschmitz after upgrading to
4.0.1
I personally am not seeing this issue anymore.Worked for me
I hope this helps.
This issue is fixed now. No error with latest versions of react-scripts and typescript.