Skip to content

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

Closed

Description

@paveltiunov

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

Activity

  1. gurpreetsingh2410 commented on Sep 29, 2019

    @gurpreetsingh2410
  2. smogili1 commented on Sep 29, 2019

    @smogili1

    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.

  3. iMerica commented on Sep 30, 2019

    @iMerica

    Downgrading React Scripts to 3.0.1 worked for me.

  4. alaindimabuyo commented on Sep 30, 2019

    @alaindimabuyo

    @iMerica downgrading also worked for me

  5. rodgomesc commented on Sep 30, 2019

    @rodgomesc

    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

  6. smogili1 commented on Sep 30, 2019

    @smogili1

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

  7. rodgomesc commented on Sep 30, 2019

    @rodgomesc

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

  8. amayatsky commented on Sep 30, 2019

    @amayatsky

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

  9. Gr8z commented on Sep 30, 2019

    @Gr8z

    npm i react-scripts@3.0.1

    Downgrade to 3.0.1

  10. mattisdada commented on Sep 30, 2019

    @mattisdada

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

  11. janprasil commented on Sep 30, 2019

    @janprasil

    I had the same issue, also downgraded to 3.0.1

  12. ncolliva commented on Sep 30, 2019

    @ncolliva

    downgrading to version 3.0.1 seems to solve the problem!

  13. oyof8376 commented on Sep 30, 2019

    @oyof8376

    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 eslint@6.5.0 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",

  14. 25 remaining items

  15. added a commit that references this issue on Sep 30, 2019
  16. ahrbil commented on Sep 30, 2019

    @ahrbil

    I have the same issue and I just spent the whole day debugging it.
    downgrading to react-scripts: 3.0.1 worked for me.

  17. naeohmi commented on Sep 30, 2019

    @naeohmi

    We're having this same issue, same error message, and it's breaking the whole build 😲!
    Tried downgrading to react-scripts: 3.0.1 but that's not quite working yet...

  18. avindra commented on Sep 30, 2019

    @avindra

    Do npm users have a way to control dependency resolutions yet? As mentioned earlier in this thread, there is a working solution for yarn users: #7753 (comment) without having to completely downgrade react-scripts

  19. richardhertzog commented on Sep 30, 2019

    @richardhertzog

    node 10.16.3 react 16.9.0 react-scripts 3.0.1 eslint 6.1.0 babel/core 7.6.2
    Is working for me using npm with no resolutions.

  20. added a commit that references this issue on Sep 30, 2019
  21. gurpreetsingh2410 commented on Sep 30, 2019

    @gurpreetsingh2410

    Do npm users have a way to control dependency resolutions yet? As mentioned earlier in this thread, there is a working solution for yarn users: #7753 (comment) without having to completely downgrade react-scripts

    I am also using npm. I resolved quickly it by deleting package.json, removing node modules directory and package-lock.json and installing back again.

  22. babalugats76 commented on Sep 30, 2019

    @babalugats76

    Ouch! I lost a whole day to this, having to methodically run npm outdated and upgrade packages one by one to find the culprit. I can confirm, however, that updating package.json to 3.0.1 and rolling back allowed my application to compile and nixed the forEach issue. My application is based on npm and create-react-app.

  23. ianschmitz commented on Sep 30, 2019

    @ianschmitz
    Contributor

    Going to lock this for now to prevent email spam to those subscribed. If anyone could spare some time to try to sort out the CI error in the Linux runs over at #7754 that would be greatly appreciated. We'll post back here when we have a fix ready to go out.

  24. locked and limited conversation to collaborators on Sep 30, 2019
  25. ianschmitz commented on Oct 1, 2019

    @ianschmitz
    Contributor

    We've got a fix in and should be releasing in the next few hours hopefully. Thanks for your patience!

  26. unpinned this issue on Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions