gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.27k stars 10.31k forks source link

Gatsby 4 - DSG builds fails when plugin options contain null #33226

Closed angeloashmore closed 3 years ago

angeloashmore commented 3 years ago

Preliminary Checks

Description

This issue is for the Gatsby 4 beta.

When a plugin contains options with null at certain depths and the site is using deferred static generation (DSG), gatsby build will fail.

[nix-shell:~/projects/tmp/gatsby-4-dsg-test]$ yarn build
yarn run v1.22.10
$ gatsby build
success open and validate gatsby-configs, load plugins - 0.678s
success onPreInit - 0.001s
success delete worker cache from previous builds - 0.002s
success initialize cache - 0.054s
success copy gatsby files - 0.050s
success Compiling Gatsby Functions - 0.130s
success onPreBootstrap - 0.138s
success createSchemaCustomization - 0.025s
success Checking for changed pages - 0.001s
success source and transform nodes - 0.727s
info Writing GraphQL type definitions to /Users/angeloashmore/projects/tmp/gatsby-4-dsg-test/.cache/schema.gql
success building schema - 0.471s
success createPages - 0.006s
success createPagesStatefully - 0.030s
info Total nodes: 38, SitePage nodes: 5 (use --verbose for breakdown)
success Checking for changed pages - 0.001s
success Cleaning up stale page-data - 0.001s
success update schema - 0.103s
success onPreExtractQueries - 0.001s
success extract queries from components - 1.050s
success write out redirect data - 0.002s
success onPostBootstrap - 0.001s
info bootstrap finished - 4.999s

 ERROR

UNHANDLED REJECTION Cannot read property 'module' of null

  TypeError: Cannot read property 'module' of null

  - print-plugins.ts:119
    [gatsby-4-dsg-test]/[gatsby]/src/schema/graphql-engine/print-plugins.ts:119:52

  - lodash.js:2669 baseClone
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2669:27

  - lodash.js:2733
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2733:34

  - lodash.js:530 arrayEach
    [gatsby-4-dsg-test]/[lodash]/lodash.js:530:11

  - lodash.js:2727 baseClone
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2727:7

  - lodash.js:2733
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2733:34

  - lodash.js:530 arrayEach
    [gatsby-4-dsg-test]/[lodash]/lodash.js:530:11

  - lodash.js:2727 baseClone
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2727:7

  - lodash.js:2733
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2733:34

  - lodash.js:530 arrayEach
    [gatsby-4-dsg-test]/[lodash]/lodash.js:530:11

  - lodash.js:2727 baseClone
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2727:7

  - lodash.js:2733
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2733:34

  - lodash.js:530 arrayEach
    [gatsby-4-dsg-test]/[lodash]/lodash.js:530:11

  - lodash.js:2727 baseClone
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2727:7

  - lodash.js:2733
    [gatsby-4-dsg-test]/[lodash]/lodash.js:2733:34

  - lodash.js:530 arrayEach
    [gatsby-4-dsg-test]/[lodash]/lodash.js:530:11

not finished run queries in workers - 0.061s

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Reproduction Link

https://github.com/angeloashmore/gatsby-4-dsg-null-bug

Steps to Reproduce

  1. Using the repo above, run gatsby build. The build will fail and print the above error.
  2. In gatsby-config.js, comment out lines 21 and 43 (where null appears).
  3. Run gatsby build. The build will succeed.

The presence of null kills the build.

Expected Result

The build succeeds with valid plugin options.

Actual Result

The build fails while processing valid plugin options.

Environment

System:
    OS: macOS 10.15.6
    CPU: (12) x64 Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz
    Shell: 4.4.23 - /nix/store/n6kzbax7sjy3kha78hpfh024ghbykgxa-bash-interactive-4.4-p23/bin/bash
  Binaries:
    Node: 14.17.0 - /nix/store/jvkhrd4b513zrsbbmssg07hpkjpc9bmh-nodejs-14.17.0/bin/node
    Yarn: 1.22.10 - /nix/store/6w7zwgjmyymfknyhc78r7s4s6xrbiagg-yarn-1.22.10/bin/yarn
    npm: 7.15.1 - /nix/store/v8wdcakdc4k9pbykikl7vsijq4dp6z1c-node_npm-7.15.1/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 93.0.4577.82
    Firefox: 91.0.1
    Safari: 13.1.2
  npmPackages:
    gatsby: next => 4.0.0-zz-next.1 
    gatsby-plugin-gatsby-cloud: next => 4.0.0-zz-next.1 
    gatsby-plugin-image: next => 2.0.0-zz-next.1 
    gatsby-source-prismic: next => 5.0.0-next.4 
  npmGlobalPackages:
    gatsby-plugin-prismic-previews: 5.0.0-next.5
    gatsby-source-prismic: 5.0.0-next.4

Config Flags

No flags

angeloashmore commented 3 years ago

The following PR has been opened to fix the issue: https://github.com/gatsbyjs/gatsby/pull/33227

pieh commented 3 years ago

Thanks for the report and the fix!

I merged the fix, but we will likely wait with another beta release until Monday (it's been quite a wild last few days/weeks and for today and weekend we wanted to "freeze" releases baring some absolutely critical problem, which I think this is not (?) as there is temporary workaround with commenting null fields out)

angeloashmore commented 3 years ago

Thanks @pieh! The example I linked is a bit contrived. In a real project, those schemas are fetched from an API and populated in plugin options (or provided manually like in the example).

While this is a blocker for all Prismic projects, a Monday release is reasonable. Thanks again 👍

angeloashmore commented 3 years ago

Hey @pieh, any update on publishing a new beta version with this fix? Thanks!

LekoArts commented 3 years ago

Hey @angeloashmore - this was released in the meantime on the next tag :)

angeloashmore commented 3 years ago

Thanks for the update @LekoArts!