create-react-app: 4.0 alpha - TypeError: Cannot add property noFallthroughCasesInSwitch, object is not extensible
Describe the bug
I updated a typescript CRA project (previously on ^3.4.0
react-scripts version) to use react-scripts “next” version to try out 4.0 alpha (following https://gist.github.com/iansu/282dbe3d722bd7231fa3224c0f403fa1), but encountered this error when running yarn start
yarn run v1.22.4
$ craco start
/Users/kwuang/github/suma-web/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:210
appTsConfig.compilerOptions[option] = suggested;
^
TypeError: Cannot add property noFallthroughCasesInSwitch, object is not extensible
at verifyTypeScriptSetup (/Users/kwuang/github/suma-web/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:210:45)
at Object.<anonymous> (/Users/kwuang/github/suma-web/node_modules/react-scripts/scripts/start.js:31:1)
at Module._compile (internal/modules/cjs/loader.js:1151:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Module.require (internal/modules/cjs/loader.js:1040:19)
at require (internal/modules/cjs/helpers.js:72:18)
at start (/Users/kwuang/github/suma-web/node_modules/@craco/craco/lib/cra.js:202:5)
at Object.<anonymous> (/Users/kwuang/github/suma-web/node_modules/@craco/craco/scripts/start.js:27:1)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Did you try recovering your dependencies?
(Write your answer here.)
Which terms did you search for in User Guide?
(Write your answer here if relevant.)
Environment
Environment Info:
current version of create-react-app: 3.4.1
running from /Users/kwuang/github/suma-web/node_modules/create-react-app
System:
OS: macOS 10.15.3
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Binaries:
Node: 13.7.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.13.6 - /usr/local/bin/npm
Browsers:
Chrome: 84.0.4147.105
Firefox: 74.0.1
Safari: 13.0.5
npmPackages:
react: ^16.13.1 => 16.13.1 (16.12.0)
react-dom: ^16.13.1 => 16.13.1 (16.12.0)
react-scripts: next => 4.0.0-next.77+3d74b79d
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
(Write your steps here:)
- change to
next
version of react-scripts inpackage.json
yarn
to install new depsyarn start
Expected behavior
Expected yarn start
to work as before.
Actual behavior
Has console output (see above).
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 154
- Comments: 52 (3 by maintainers)
Commits related to this issue
- build: upgrade react-scripts to v4 This also updates to React 17, eslint 7, TypeScript v4, etc. - React 17 has no new features, but does have a few breaking changes that shouldn't affect bsd. (https:... — committed to votingworks/bsd by eventualbuddha 4 years ago
- :boom: yarn upgrade --latest about `"noFallthroughCasesInSwitch": true`: https://github.com/facebook/create-react-app/issues/9429 — committed to polamjag/assign-omikuji-2020 by polamjag 4 years ago
- Temporary fix for bug in react-scripts See https://github.com/facebook/create-react-app/issues/9429 — committed to haggen/localthreat by haggen 4 years ago
- Temporary fix for bug in react-scripts See https://github.com/facebook/create-react-app/issues/9429 — committed to haggen/localthreat by haggen 4 years ago
- upgrade typescript, react and react scripts necessary fixes: https://stackoverflow.com/questions/63660520/typescript-error-after-upgrading-version-4-useparams-from-react-router-dom-pr https://github.... — committed to dracor-org/einakter by cmil 4 years ago
- fix: #123 switch noFallthroughCasesInSwitch to true https://github.com/facebook/create-react-app/issues/9429 — committed to alexandr-g/cra-template-typescript-redux by alexandr-g 4 years ago
- Specify noFallthgouhCasesInSwitch to work around tsconfig issue More info: https://github.com/facebook/create-react-app/issues/9429 — committed to CMSgov/easi-app by deleted user 4 years ago
- Add workaround to CRA 4.0 issue https://github.com/facebook/create-react-app/issues/9429 — committed to Coteh/cra-template-typescript-pretty by Coteh 4 years ago
- build: upgrade react-scripts to v4 This also updates to React 17, eslint 7, TypeScript v4, etc. - React 17 has no new features, but does have a few breaking changes that shouldn't affect bsd. (https:... — committed to votingworks/vxsuite by eventualbuddha 4 years ago
- Work round misbehaviour with react-scripts 4 Ugh; see https://github.com/facebook/create-react-app/issues/9429 for details. — committed to pytchlang/pytch-webapp by bennorth 4 years ago
- Add workaround for react-scripts glitch See: https://github.com/facebook/create-react-app/issues/9429. — committed to tanem/state-machines-in-react by tanem 4 years ago
- fix TypeError: Cannot add property noFallthroughCasesInSwitch https://github.com/facebook/create-react-app/issues/9429#issuecomment-715411571 — committed to gawaooooo-sandbox/react-custom-hooks-practice by gawaooooo 4 years ago
- fix: Cannot add property noFallthroughCasesInSwitch, object is not extensible https://github.com/facebook/create-react-app/issues/9429 — committed to CraftyDragon678/dimiLFM-web by CraftyDragon678 4 years ago
- Update to react-scripts@4.0.0 React-scripts has been upgraded. The tsconfig had to be edited in order to bypass an error. Ref: https://github.com/facebook/create-react-app/issues/9429#issuecomment-6... — committed to blockofmagic/front by schettn 4 years ago
- Temp fix for incompat issue with react-scripts 4.0.0 and TS See: https://github.com/facebook/create-react-app/issues/9429 https://github.com/facebook/create-react-app/issues/9868 — committed to jobsgowhere/jobsgowhere by SheldonCheng 4 years ago
- feat: temp bug fixed https://github.com/facebook/create-react-app/issues/9429 — committed to s-ong-c/cra-template-songc by s-ong-c 4 years ago
- fix: noFallthroughCasesInSwitch missing in tsconfig.json Error Message: TypeError: Cannot add property noFallthroughCasesInSwitch, object is not extensible Issue: https://github.com/facebook/create-... — committed to wijloc/github-explorer by wijloc 4 years ago
- Add workaround for react-scripts glitch See: https://github.com/facebook/create-react-app/issues/9429. — committed to tanem/state-machines-in-react by tanem 4 years ago
- desperate attempt to make TS work. https://github.com/facebook/create-react-app/issues/9429#issuecomment-674994709 — committed to au3pm/au3pm.github.io by genius257 3 years ago
- fix: #123 switch noFallthroughCasesInSwitch to true https://github.com/facebook/create-react-app/issues/9429 — committed to guilsuper/cra-template-typescript-redux by guilsuper 4 years ago
I was able to sidestep this error by adding
"noFallthroughCasesInSwitch": true
tocompilerOptions
in mytsconfig.json
(which I think just avoids the need for this code to run at all).I also got that too. Just figured out that I have to change
"compilerOptions.jsx"
from"preserve"
to"react"
.Didn’t read too much in to this but this seems to be working for me. Not sure why Immer is being used in this case where the readTsConfig object doesn’t seem to be changed at all? Guessing there’s some need for a shallow or deep copy of
readTsConfig
?verifyTypeScriptSetup.js
Before:
After:
Now this problem is released. Why this one is ignored and lib is released with the critical bugs?
@ianschmitz What about
paths
? I know this issue was specifically aboutnoFallthroughCasesInSwitch
, but many people complained aboutpaths
here as well and it’s from the same family of issues.I am getting a similar error, but for a different property…
I know that
paths
are technically not supported by CRA, but I’ve been using that with the current stable version just fine. Please, don’t make it harder than it is already. There is no practical reason whypaths
should be banned from use.@flppv It still doesn’t solve the “paths”, because that’s an object and no just primitive value. I am surprised they published 4.0.0 without handling such a “major” flaw.
CRA 4.0.0 has been released today and I encountered this same bug in the released version when trying to upgrade to it.
It seems like this issue should have been expected and easy to fix. i.e. The
config
value fromreadConfigFile
should be considered immutable and CRA should not be modifying it.Same issue here and fixed with the
"noFallthroughCasesInSwitch": true
solution above.Don’t really get why this was closed when this is still breaking when upgrading from an existing project to CRA 4. The above change from https://github.com/facebook/create-react-app/issues/9429#issuecomment-669615656 @jamsch works - so can we please release this soon as a quick patch?
I have another version of this. After adding
noFallthroughCasesInSwitch
like suggested above I get this error:@ianschmitz I honestly haven’t tried, but seeing 30+ people giving 👍 and seeing this still present in the code, I don’t think it’s handled 😃
https://github.com/facebook/create-react-app/blob/aec42e2cc05fe0799a3b73830b874757e9e3f561/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js#L159
Fixed in #9921.
@jamsch I can confirm that the above change fixed it for me. 🙂
Side note on this: we just ran into this issue upgrading our React app to react-scripts v4. Running
yarn start
resulted in this error, but runningyarn build
did add"noFallthroughCasesInSwitch": true
to ourtsconfig.json
file. After that, runningyarn start
worked.Note: this also happens if you have configured
paths
in your tsconfig. I have a set up with “react-app-rewired” in a monorepo with some webpack overrides to accommodate for paths. This bug prevents me from using v4 at all.@FredyC this is not true, CRA 3 wasn’t forbidding the definition of the
paths
property in tsconfig, and that was nice for monorepo, for alias support. Heck, even till4.0.0-next.64
it was totally fine to use it! Now CRA 4 basically breaks typescript monorepo due to this new enforcement, without providing any reason as of why this is not allowed anymore.hey guys! (@Annihil, @jamsch, @rizkyramadhan, …whoever needs it)
Tried this workaround for monorepo (with Lerna) - and it worked for me. relevant for those who have “paths” entry on his
tsconfig.json
file.using
patch-package
, I commented out row159
onreact-scripts/scripts/utils/verifyTypeScriptSetup.js
, So patch file will be looked like that:this allows me to maintain the path entry, and so far didn’t found it break anything. will update otherwise. vscode still type suggestions still works 😃
P.S, using
react-app-rewired
as well, and adding aliases…After upgrading with
yarn upgrade-interactive --latest
I’m getting the mentioned noFallthroughCasesInSwitch error when I try toyarn start
. Deleting and redownloading node_moduels didn’t help either.Edit: So I’ve created a fresh 4.0.0 CRA and it seems that my dependencies are same except there is now a
"web-vitals": "^0.2.4"
dependency, not sure why that’s there.Most importanlty
tsconfig.json
now has the"noFallthroughCasesInSwitch": true,
set by defualt, so it’s not a workaround to set it but the default behaviour. I feel like that this should definitely be mentioned in the upgrade guide.@michchan
Adding
"jsx: "react"
does not fix the issue. In fact, if you addjsx: "preserve"
, the script may still run fine. It only throws if you don’t specify some of the options intsconfig.json
that have suggested values. When you do that the code assigning the suggested value is executed and crashes the script.For example the script will crash if you omit the
allowJs
option which can be suggested, the same can be applied to many other options but most of them exceptnoFallthroughCasesInSwitch
are already specified in the defaulttsconfig.json
.I’ve tried adding
Thanks for this, confirming it worked for me too! On its own,
"noFallthroughCasesInSwitch": true
didn’t fix the issue. But adding"jsx: "react"
has completely resolved it for me.#9921 is included with
react-scripts
v4.0.1. This also fixes thepaths
property.Upgraded from
react-scripts
3.4.3 to 4.0.0, got the same issue (as the topic starter).This helped https://github.com/facebook/create-react-app/issues/9429#issuecomment-669615656 Applied the change as a patch to
react-scripts
module.Deleting
tsconfig.json
doesn’t help, since the generated file does not match my preference and if I update it, the build fails again.Looks like the fix has been merged but not released yet https://github.com/facebook/create-react-app/pull/9921
Yeah for evreyone else I can confirm that it works only when both changes listed above are applied
You can create a new
tsconfig.json
file by runningtsc --init
.Without
paths
property in tsconfig,ts-jest
also breaks in a monorepo. Falling back to4.0.0-next.64
I’m also seeing the above (noFallthroughCasesInSwitch object is not extensible) error, even after running npm ci As mentioned above, adding this to tsconfig.json “noFallthroughCasesInSwitch”: true seems to have fixed that error
also getting this error
Also faced error
Cannot add property noFallthroughCasesInSwitch, object is not extensible
, and added"noFallthroughCasesInSwitch": true
to my tsconfig.json. But after that I got this:Cannot read property 'use' of undefined
. Has anyone faced this issue too? There are my logs:P.S. I’d also tried to set up
noFallthroughCasesInSwitch
to false, but this didn’t help 😕@FredyC does the fix not work for paths?
Adding this to
tsconfig.json
fixed it for me too@michchan I can confirm on my local machine that the crash doesn’t depend on which values you provide to the compiler options, it depends on whether or not the options are specified in your
tsconfig.json
. You should not use the fix from https://github.com/facebook/create-react-app/issues/9429#issuecomment-669615656 because it’s invasive, hard to maintain, and it may lead to other bugs since it changes the behavior of the script.The proposed solution in my https://github.com/facebook/create-react-app/issues/9429#issuecomment-715903925 is not evasive and easier to implement, without meddling with anything inside the
node_modules
Maybe there should be a
SKIP_TS_SETUP_CHECK
flag, similar toSKIP_PREFLIGHT_CHECK
https://github.com/facebook/create-react-app/blob/d5c0fe287a6bc24c60ee52ca768bdf3a10b937e1/packages/react-scripts/scripts/start.js#L22-L32
This fixed the issue, but vscode cannot recognise the paths, it is a deal breaker for me