为什么收到“期望JSON为GraphQL可为null的类型”。使用Gatsby和Netlify进行构建时?

时间:2019-08-23 19:05:13

标签: graphql gatsby

尝试部署到Netlify时遇到错误。自上次构建以来,我没有更改任何真正重要的内容,只是更新了有关运输政策的一些文字。这是我的项目存储库,仅供参考https://github.com/ThermalIDTechnologies/up-safety-solutions

我以前的版本工作正常。它可能与gatsby-source-prismic插件有关。我尝试将所有依赖项更新到最新版本,但仍然收到相同的错误。在本地运行构建会收到相同的错误。

这是来自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

这是本地错误:

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.

1 个答案:

答案 0 :(得分:0)

对我来说,以下是正确的。当我运行gatsby develop时,遇到了另一个错误,该错误会进一步解释该问题。

  

错误:无法从另一个模块或领域使用GraphQLScalarType“ JSON”。     确保node_modules中只有一个“ graphql”实例     目录。如果“ graphql”的不同版本是其他版本的依赖项     依赖模块,请使用“分辨率”来确保仅安装一个版本。     https://yarnpkg.com/en/docs/selective-version-resolutions     重复的“ graphql”模块不能同时使用,因为不同     版本可能具有不同的功能和行为。来自一个的数据     在另一个函数中使用的版本可能会产生混淆,并且     虚假结果。

yarn.lock有一些依赖关系,依赖于graphql的不同版本。这导致构建无法正常工作。

删除node_modulesyarn.lock并运行yarn install解决了该问题,但是我不知道删除yarn.lock是否是一个好习惯。


更新

运行yarn upgrade修复了yarn.lock中的依赖项。