TypeError: Cannot read property 'forEach' of undefined if object destructing with rest props is used
Describe the bug
Compilation fails with TypeError: Cannot read property 'forEach' of undefined if object destructing with rest props is used in npx created app.
Works with yarn though.
Versions of react-scripts affected: 3.1.0, 3.1.1 (with different error messages), 3.1.2 Most recent react-scripts version that works: 3.0.1
Did you try recovering your dependencies?
npm --version: 6.11.3
Which terms did you search for in User Guide?
TypeError: Cannot read property 'forEach' of undefined
Environment
$ npx create-react-app --info
Environment Info:
System:
OS: macOS 10.14
CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
Binaries:
Node: 12.11.0 - ~/.nvm/versions/node/v12.11.0/bin/node
Yarn: Not Found
npm: 6.11.3 - ~/.nvm/versions/node/v12.11.0/bin/npm
Browsers:
Chrome: 77.0.3865.90
Firefox: 67.0
Safari: 12.0
npmPackages:
react: ^16.10.1 => 16.10.1
react-dom: ^16.10.1 => 16.10.1
react-scripts: 3.1.2 => 3.1.2
npmGlobalPackages:
create-react-app: Not Found
(paste the output of the command here.)
Steps to reproduce
(Write your steps here:)
- Create new app using npx:
$ npx create-react-app error-test. Make sureyarnis not installed. - Go to
error-test/src/App.jsand add following code to the end of the file:
const testCase = {
restObjectPropsFails: ({ id, ...item }) => {
return null;
}
}
- Run
$ npm startfromerror-testdirectory
Expected behavior
Application is compiled correctly
Actual behavior
Compilation failed with message:
Failed to compile.
./src/App.js
TypeError: Cannot read property 'forEach' of undefined
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
+1
Ran into the same issue and spent half a day debugging. Saw this issue and switched to a prior version and it seems to work like a charm.
Downgrading React Scripts to 3.0.1 worked for me.
@iMerica downgrading also worked for me
Downgrading React Scripts to 3.0.1 worked for me.
i was working on a project for one week, with react-scripts version 3.0.1 with no errors, and today when i start my project i got this related error, what is the explanation for this? react-scripts connect to a external server when i run yarn start ???? this is insane
PS: downgrading to version 3.0.1 solved the problem
you must have done yarn install which would have upgraded based on your package.json settings.
No, in all commits, version of react Scripts never change, i Just checkout a old commits to check
3.1.1 is working fine for me while 3.1.2 doesn't.
+1 I also had to downgrade to 3.0.1.
3.1.2 & 3.1.1 (I didn't try 3.1.0) both failed....
I had the same issue, also downgraded to 3.0.1
downgrading to version 3.0.1 seems to solve the problem!
I had the same problem but found that reverting eslint to 6.4.0 from the simultaneous update to 6.5.0 solved the problem. Tried to npm i [email protected] again and got same compile error. So working with: "eslint": "^6.4.0", "react": "^16.10.1", "react-dom": "^16.10.1", "react-router-dom": "^5.1.1", "react-scripts": "^3.1.2",
ESLint bug: https://github.com/eslint/eslint/issues/12335
+1 getting same issue. Same code was working on Friday. Its caused after npm install and updated packages version. You can downgrade react-script version to 3.0.1 to fix this. But looks like issue is in eslint.
+1 getting same issue
+1 same issue
+1 Same issue
+1 Same issue downgrading react-scripts doesn't work for me
Had the same issue. Resolved by:
- downgraded react-scripts to 3.0.1
- removed eslint from devDependencies
- removed package-lock.json, deleted node_modules and run "npm install"