leebenson / reactql

Universal React+GraphQL starter kit: React 16, Apollo 2, MobX, Emotion, Webpack 4, GraphQL Code Generator, React Router 4, PostCSS, SSR
https://reactql.org
MIT License
1.82k stars 173 forks source link

TypeError: initial.siblings.map(...).map(...).concat(...).flat is not a function #144

Closed Shackless closed 5 years ago

Shackless commented 5 years ago

With the latest release, I get the following error after trying to load the start page:

Error: TypeError: initial.siblings.map(...).map(...).concat(...).flat is not a function
    at Stats.scripts (C:\Source\reactql\src\lib\stats.ts:63:8)
    at eval (webpack-internal:///./src/entry/server.tsx:72:30)
    at process._tickCallback (internal/process/next_tick.js:68:7)

To reproduce the error, just clone the repo, run npm i and npm start. Then navigate to http://localhost:3000.

ZimboQC commented 5 years ago

I’ve got this error with nodejs 10.5. Upgrade to 11.8 to solve it

Shackless commented 5 years ago

Thanks, that fixed it!

leebenson commented 5 years ago

yeah, this is relatively new in V8, so it'll only work with the current Node branch, and not LTS.

I should probably update that for LTS compatibility.

JoeApperson commented 5 years ago

Since the stats module is already using lodash, a quick way to fix this problem for Node < 11 is to just change the script var's assignment to look like this:

    const scripts: string[] = lodash.flatten<string>(
      initial.siblings
        .map((sibling: any) =>
          this.raw.chunks.find((chunk: any) => chunk.id === sibling)
        )
        .map((sibling: any) => sibling.files)
        .concat(initial.files))
      .filter((file: string) => file.endsWith(".js"))
      .map((file: string) => `/${file}`);