Up Safety Solutions
Up Safety Solutions

Reputation: 1

Why am I receiving " Expected JSON to be a GraphQL nullable type." when building with Gatsby and Netlify?

I am running into an error when trying to deploy to Netlify. I haven't changed anything really crucial since the last build, just updated some text on a shipping policy. This is my project repository for reference https://github.com/ThermalIDTechnologies/up-safety-solutions.

My previous build worked just fine. It probably has something to do with the gatsby-source-prismic plugin. I've tried updating all my dependencies to the latest versions and still receiving the same error. Running build locally receives the same error.

Here is the error from Netlify:

10:04:25 AM: success open and validate gatsby-configs — 0.108
10:04:26 AM: error Expected JSON to be a GraphQL nullable type.
10:04:26 AM: Error in "/opt/build/repo/node_modules/gatsby-source-prismic/gatsby-node.js": Expected JSON to be a GraphQL nullable type.
10:04:26 AM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
10:04:26 AM: 
10:04:26 AM:   Error: Expected JSON to be a GraphQL nullable type.
10:04:26 AM:   
10:04:26 AM:   - default.js:20 Object.<anonymous>
10:04:26 AM:     [repo]/[gatsby-source-prismic]/[graphql-compose]/lib/directive/default.js:20    :13
10:04:26 AM:   
10:04:26 AM:   - v8-compile-cache.js:178 Module._compile
10:04:26 AM:     [repo]/[v8-compile-cache]/v8-compile-cache.js:178:30
10:04:26 AM:   
10:04:26 AM:   - loader.js:789 Object.Module._extensions..js
10:04:26 AM:     internal/modules/cjs/loader.js:789:10
10:04:26 AM:   
10:04:26 AM:   - loader.js:653 Module.load
10:04:26 AM:     internal/modules/cjs/loader.js:653:32
10:04:26 AM:   
10:04:26 AM:   - loader.js:593 tryModuleLoad
10:04:26 AM:     internal/modules/cjs/loader.js:593:12
10:04:26 AM:   
10:04:26 AM:   - loader.js:585 Function.Module._load
10:04:26 AM:     internal/modules/cjs/loader.js:585:3
10:04:26 AM:   
10:04:26 AM:   - loader.js:692 Module.require
10:04:26 AM:     internal/modules/cjs/loader.js:692:17
10:04:26 AM:   
10:04:26 AM:   - v8-compile-cache.js:159 require
10:04:26 AM:     [repo]/[v8-compile-cache]/v8-compile-cache.js:159:20
10:04:26 AM:   
10:04:26 AM:   - SchemaComposer.js:36 Object.<anonymous>
10:04:26 AM:     [repo]/[gatsby-source-prismic]/[graphql-compose]/lib/SchemaComposer.js:36:39  
10:04:26 AM:   - v8-compile-cache.js:178 Module._compile
10:04:26 AM:     [repo]/[v8-compile-cache]/v8-compile-cache.js:178:30
10:04:26 AM:   
10:04:26 AM:   - loader.js:789 Object.Module._extensions..js
10:04:26 AM:     internal/modules/cjs/loader.js:789:10
10:04:26 AM:   
10:04:26 AM:   - loader.js:653 Module.load
10:04:26 AM:     internal/modules/cjs/loader.js:653:32
10:04:26 AM:   
10:04:26 AM:   - loader.js:593 tryModuleLoad
10:04:26 AM:     internal/modules/cjs/loader.js:593:12
10:04:26 AM:   
10:04:26 AM: 
10:04:27 AM: Skipping functions preparation step: no functions directory set
10:04:27 AM: Caching artifacts
10:04:27 AM: Started saving node modules
10:04:27 AM: Finished saving node modules
10:04:27 AM: Started saving yarn cache
10:04:27 AM: Finished saving yarn cache
10:04:27 AM: Started saving pip cache
10:04:27 AM: Finished saving pip cache
10:04:27 AM: Started saving emacs cask dependencies
10:04:27 AM: Finished saving emacs cask dependencies
10:04:27 AM: Started saving maven dependencies
10:04:27 AM: Finished saving maven dependencies
10:04:27 AM: Started saving boot dependencies
10:04:27 AM: Finished saving boot dependencies
10:04:27 AM: Started saving go dependencies
10:04:27 AM: Finished saving go dependencies
10:04:33 AM: Error running command: Build script returned non-zero exit code: 1
10:04:33 AM: Failing build: Failed to build site
10:04:33 AM: failed during stage 'building site': Build script returned non-zero exit code: 1
10:04:33 AM: Finished processing build request in 1m45.555296927s

And here is the error locally:

ERROR

Error in "C:\Users\Admin\Desktop\Development\up-safety-solutions-master\node_modules\gatsby-source-prismic\gatsby-node.js": Expected JSON to be a GraphQL nullable type.

Upvotes: 0

Views: 1242

Answers (1)

Aaron Hakala
Aaron Hakala

Reputation: 302

For me the following was true. When I ran gatsby develop I got a different error that explains the issue a bit more.

Error: Cannot use GraphQLScalarType "JSON" from another module or realm. Ensure that there is only one instance of "graphql" in the node_modules directory. If different versions of "graphql" are the dependencies of other relied on modules, use "resolutions" to ensure only one version is installed. https://yarnpkg.com/en/docs/selective-version-resolutions Duplicate "graphql" modules cannot be used at the same time since different versions may have different capabilities and behavior. The data from one version used in the function from another could produce confusing and spurious results.

yarn.lock had a few dependencies which depended on different versions of graphql. This resulted in the build not working.

Deleting node_modules and yarn.lock and running yarn install resolved the issue, but I don't know if deleting yarn.lock is good practice.


UPDATE

Running yarn upgrade fixed the dependencies in yarn.lock.

Upvotes: 2

Related Questions