create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'

Open aadityarajkumawat opened this issue 6 years ago • 62 comments

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.

aadityarajkumawat avatar Nov 20 '20 08:11 aadityarajkumawat

I have this happening after upgrading to typescript 4.1

roderik avatar Nov 20 '20 08:11 roderik

Duplicate with https://github.com/facebook/create-react-app/issues/9868

maltoze avatar Nov 20 '20 08:11 maltoze

Same issue I am facing. Just ran the npx create-react-app my-app --template typescript command. When I run it using yarn start, I get this error.

convexhull avatar Nov 20 '20 09:11 convexhull

+1 Me too.

LiuJun0 avatar Nov 20 '20 09:11 LiuJun0

Duplicate of #9868

n1ru4l avatar Nov 20 '20 10:11 n1ru4l

Definitely, a Duplicate of #9868 but also can confirm getting the following error: -

TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'
    at verifyTypeScriptSetup (/Users/Nathan/Projects/pwa/pwa-react/pwa-react/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:239:43)
    at Object.<anonymous> (/Users/Nathan/Projects/pwa/pwa-react/pwa-react/node_modules/react-scripts/scripts/start.js:31:1)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
error Command failed with exit code 1.

NathanScott85 avatar Nov 20 '20 10:11 NathanScott85

+1 seeing this as well

grug avatar Nov 20 '20 10:11 grug

+1 Now i can't create new typescript anymore !!!

LenChang avatar Nov 20 '20 10:11 LenChang

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.

ChristianIvicevic avatar Nov 20 '20 11:11 ChristianIvicevic

I've just had this exact error, the problem is increate-react-app\packages\react-scripts\scripts\utils\verifyTypeScriptSetup.js on Line 151 (to find it search for ts.JsxEmit.ReactJ) it was using ts.JsxEmit.ReactJsx but should use ts.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?

dnepro avatar Nov 20 '20 12:11 dnepro

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.

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.

convexhull avatar Nov 20 '20 13:11 convexhull

please solve this . i have this error too.

neonise avatar Nov 20 '20 14:11 neonise

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 with npm start

jaquinocode avatar Nov 20 '20 19:11 jaquinocode

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.

bartlettpsj avatar Nov 20 '20 20:11 bartlettpsj

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.

It works and the generated file is actually identical

wannymiarelli avatar Nov 20 '20 20:11 wannymiarelli

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

Earle-Poole avatar Nov 20 '20 20:11 Earle-Poole

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.

Yooo. Thanks

matiasgdev avatar Nov 20 '20 23:11 matiasgdev

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

longbucks avatar Nov 21 '20 00:11 longbucks

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

This is not a solution in any kind of production environment that uses a VCS that ignores the node_modules directory.

Earle-Poole avatar Nov 21 '20 01:11 Earle-Poole

Solution

Change typescript version in package.json "typescript": "~4.0.5",

Change in tsconfig.json "jsx": "react"

In the terminal

yarn install 
yarn start

dyangua avatar Nov 21 '20 03:11 dyangua