graphql - 为什么我会收到“预期的 JSON 是 GraphQL 可为空的类型”。使用 Gatsby 和 Netlify 构建时?
问题描述
尝试部署到 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.
解决方案
对我来说,以下是正确的。当我运行时,gatsby develop
我得到了一个不同的错误,可以更多地解释这个问题。
错误:无法使用来自另一个模块或领域的 GraphQLScalarType“JSON”。确保 node_modules 目录中只有一个“graphql”实例。如果不同版本的“graphql”是其他依赖模块的依赖,使用“resolutions”确保只安装一个版本。 https://yarnpkg.com/en/docs/selective-version-resolutions 不能同时使用重复的“graphql”模块,因为不同的版本可能具有不同的功能和行为。来自另一个版本的函数中使用的数据可能会产生令人困惑和虚假的结果。
yarn.lock
有一些依赖于不同版本的graphql。这导致构建无法正常工作。
删除node_modules
并yarn.lock
运行yarn install
解决了这个问题,但我不知道删除yarn.lock
是否是好的做法。
更新
运行yarn upgrade
修复了 yarn.lock 中的依赖关系。
推荐阅读
- c# - CefSharp vb.net 的 SetProxy
- node.js - 有没有办法在 TLS 协商期间或之后访问 HTTPS 中的 PSK 身份
- session - 服务器何时向客户端发送 CSRF 令牌?
- react-native - react-native-background-fetch,在根 index.js 中声明的函数是否需要无头背景?
- vhdl - 从 Modelsim 中的 VHDL 测试台中提取对象/信号的输出值到 .txt 文件
- react-redux - 为什么 RTK 查询响应处理不起作用?
- c++ - 非类型模板参数特化
- flutter - 当满足 if 条件时,我无法使用颤振音频播放器播放音频,我不想在按下按钮时播放音频
- gcc - 如何使用 gcc 成功编译 .cpp 文件而不添加 -lstdc++ 标志?
- swift - 从 tvOS swift 上的 m3u8 播放列表中选择 AVPlayer 中的频道和字幕