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

TypeError: Cannot read property 'forEach' of undefined if object destructing with rest props is used

Open paveltiunov opened this issue 7 years ago • 41 comments

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:)

  1. Create new app using npx: $ npx create-react-app error-test. Make sure yarn is not installed.
  2. Go to error-test/src/App.js and add following code to the end of the file:
const testCase = {
  restObjectPropsFails: ({ id, ...item }) => {
    return null;
  }
}
  1. Run $ npm start from error-test directory

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.)

paveltiunov avatar Sep 29 '19 20:09 paveltiunov

+1

gurpreetsingh2410 avatar Sep 29 '19 23:09 gurpreetsingh2410

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.

smogili1 avatar Sep 29 '19 23:09 smogili1

Downgrading React Scripts to 3.0.1 worked for me.

iMerica avatar Sep 30 '19 02:09 iMerica

@iMerica downgrading also worked for me

alaindimabuyo avatar Sep 30 '19 03:09 alaindimabuyo

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

rodgomesc avatar Sep 30 '19 04:09 rodgomesc

you must have done yarn install which would have upgraded based on your package.json settings.

smogili1 avatar Sep 30 '19 05:09 smogili1

No, in all commits, version of react Scripts never change, i Just checkout a old commits to check

rodgomesc avatar Sep 30 '19 05:09 rodgomesc

3.1.1 is working fine for me while 3.1.2 doesn't.

amayatsky avatar Sep 30 '19 05:09 amayatsky

npm i [email protected]

Downgrade to 3.0.1

Gr8z avatar Sep 30 '19 06:09 Gr8z

+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....

mattisdada avatar Sep 30 '19 06:09 mattisdada

I had the same issue, also downgraded to 3.0.1

janprasil avatar Sep 30 '19 06:09 janprasil

downgrading to version 3.0.1 seems to solve the problem!

ncolliva avatar Sep 30 '19 06:09 ncolliva

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",

oyof8376 avatar Sep 30 '19 08:09 oyof8376

ESLint bug: https://github.com/eslint/eslint/issues/12335

targos avatar Sep 30 '19 08:09 targos

+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.

AbhaysinghBhosale avatar Sep 30 '19 09:09 AbhaysinghBhosale

+1 getting same issue

jembach avatar Sep 30 '19 09:09 jembach

+1 same issue

paul-vd avatar Sep 30 '19 09:09 paul-vd

+1 Same issue

Bhargav-Narayan avatar Sep 30 '19 09:09 Bhargav-Narayan

+1 Same issue downgrading react-scripts doesn't work for me

adelsagemilang avatar Sep 30 '19 09:09 adelsagemilang

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"

alexeysmorkalov avatar Sep 30 '19 09:09 alexeysmorkalov