Create-react-app: Unable to use typescript 4 with react-scripts 4 and npm 7.0.5

Created on 24 Oct 2020  路  8Comments  路  Source: facebook/create-react-app

One of the release notes for 4.0.0 is support for typescript v4,
so as a user I'd expect to be able to use typescript 4 with react-scripts 4.0.0.

Case:
package.json with react-scripts 4.0.0 and typescript 4.0.3 with npm on latest (7.0.5)

Result:
image

Expected:
No error

Fallback: Use ts 3.9.7

bug report needs triage

Most helpful comment

I am having this issue as well, but with TS 3.9.7, and npm 6.14.7.

After running npm install react-scripts@latest

$ npm start

> [email protected] start D:\dev\js\project
> react-scripts start

D:\dev\js\project\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:231
        appTsConfig.compilerOptions[option] = suggested;
                                            ^

TypeError: Cannot add property noFallthroughCasesInSwitch, object is not extensible
    at verifyTypeScriptSetup (D:\dev\js\project\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:231:45)
    at Object.<anonymous> (D:\dev\js\project\node_modules\react-scripts\scripts\start.js:31:1)
    at Module._compile (internal/modules/cjs/loader.js:1251:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
    at Module.load (internal/modules/cjs/loader.js:1100:32)
    at Function.Module._load (internal/modules/cjs/loader.js:962:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

All 8 comments

Have you tried delete your yarn.lock/package-lock.json and install again?

I just upgraded one of my projects and typescript 4 support is fine.

@malcolm-kee very much so. Are you also using npm v7.0.5?

image

@MichaelHindley opps, I am using npm 6. Sorry I miss out that 馃槄

I've got the same issue - npm v7.0.3, react-scripts v4.0.0

I am having this issue as well, but with TS 3.9.7, and npm 6.14.7.

After running npm install react-scripts@latest

$ npm start

> [email protected] start D:\dev\js\project
> react-scripts start

D:\dev\js\project\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:231
        appTsConfig.compilerOptions[option] = suggested;
                                            ^

TypeError: Cannot add property noFallthroughCasesInSwitch, object is not extensible
    at verifyTypeScriptSetup (D:\dev\js\project\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:231:45)
    at Object.<anonymous> (D:\dev\js\project\node_modules\react-scripts\scripts\start.js:31:1)
    at Module._compile (internal/modules/cjs/loader.js:1251:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1272:10)
    at Module.load (internal/modules/cjs/loader.js:1100:32)
    at Function.Module._load (internal/modules/cjs/loader.js:962:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Add "noFallthroughCasesInSwitch": true, to your tsconfig.json.

Can I suggest that this little tidbit be added to the Release Notes? (I know that's not on you @ggascoigne)

sorry I would have written a longer reply at the time but I was on the phone chatting to someone with this exactly problem at the time :)

I actually found this snippet in another variation of this bug elsewhere in this repo. I think that the cause is something to do with the assumptions about what the expected config is have changed and there's no automated migration.

But, yes, adding this to the release notes and or upgrading the error handling with a more useful error message would be neat.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Evan-GK picture Evan-GK  路  3Comments

adrice727 picture adrice727  路  3Comments

wereHamster picture wereHamster  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments