gatsby 无法获取有关 vercel 生产的所有 graphql 数据

如何解决gatsby 无法获取有关 vercel 生产的所有 graphql 数据

我正在使用 GatsbyContentful 开发 Headless 电子商务网站。 ShopifyNacelle

如果我使用 npm run dev 运行应用程序,它工作正常,我可以看到来自 Contentful 的所有 graphql 数据。

这就是我的意思,即使是 npm run build 也可以在本地获取所有 graphql 数据,但它不会在生产中编译所有 graphql 数据。

以下是在 Vercel 上构建 gatsby 应用程序时的一些日志。

日志说没有错误,但我可以从那里看到一些警告。

enter image description here

enter image description here

这是 graphql 查询,它在本地环境中运行良好。


const HomePage = ({ data }) => {
  console.log('slider in index page---',data);
  ...
}

export const query = graphql`
  query {
    homepageSlider: nacelleContent(type: { eq: "heroBanner" },handle: { eq: "home-slider" }) {
      title
      remoteFields
      featuredMedia {
        remoteImage {
          childImageSharp {
            gatsbyImageData(height: 2500,placeholder: TRACED_SVG)
          }
        }
      }
    }
    benefits: nacelleContent(type: { eq: "list" },handle: { eq: "benefits" }) {
      handle
      title
      remoteFields
    }
    certificates: ...
    testimonial: ...
    satisfacts: ...
    collections: ...
  }
}

 

如果我检查 vercel 上的控制台日志,它会说所有数据都有 null,除了 collections

但是如果我在本地环境中检查控制台日志,所有数据都存在。

enter image description here

为什么会这样?这似乎是 gatsby 或 vercel 问题。

// package.json

...
"dependencies": {
    "@contentful/rich-text-from-markdown": "^15.0.0","@contentful/rich-text-react-renderer": "^15.0.0","@contentful/rich-text-types": "^15.0.0","@emotion/core": "^10.0.35","@loadable/component": "^5.14.1","@nacelle/client-js-sdk": "^3.1.0","@nacelle/gatsby-source-nacelle": "^2.10.2","@nacelle/react-components": "^2.10.1","@nacelle/react-dev-utils": "^2.10.1","@nacelle/react-hooks": "^2.11.2","@nacelle/react-recharge": "^2.11.0","@react-hook/media-query": "^1.1.1","autoprefixer": "^10.2.5","change-case": "^4.1.2","fuse.js": "^6.4.1","gatsby": "^2.27.0","gatsby-alias-imports": "^1.0.6","gatsby-plugin-emotion": "^4.5.0","gatsby-plugin-fullstory": "^3.2.0","gatsby-plugin-google-tagmanager": "^3.2.0","gatsby-plugin-image": "^1.1.2","gatsby-plugin-manifest": "^3.1.0","gatsby-plugin-postcss": "^4.1.0","gatsby-plugin-react-helmet": "^4.2.0","gatsby-plugin-scroll-reveal": "0.0.7","gatsby-plugin-sharp": "^2.9.0","gatsby-plugin-transition-link": "^1.20.5","gatsby-source-filesystem": "^2.6.1","gatsby-transformer-sharp": "^2.7.0","gsap": "^3.6.1","nuka-carousel": "^4.7.7","numeral": "^2.0.6","postcss": "^8.2.8","react": "^16.13.1","react-alice-carousel": "^2.5.1","react-dom": "^16.13.1","react-helmet": "^6.1.0"
  },"devDependencies": {
    "@babel/core": "^7.11.1","@babel/plugin-proposal-optional-chaining": "^7.11.0","eslint": "^7.6.0","eslint-plugin-react": "^7.20.5","eslint-plugin-react-hooks": "^4.0.8","lint-staged": "^10.2.11","tailwindcss": "^2.0.4"
  },...
// gatsby-config.js

require('dotenv').config();

module.exports = {
  plugins: [
    {
      resolve: '@nacelle/gatsby-source-nacelle',options: {
        nacelleSpaceId: process.env.GATSBY_NACELLE_SPACE_ID,nacelleGraphqlToken: process.env.GATSBY_NACELLE_GRAPHQL_TOKEN,cmsPreviewEnabled: process.env.NACELLE_PREVIEW_MODE,contentfulPreviewSpaceId: process.env.CONTENTFUL_PREVIEW_SPACE_ID,contentfulPreviewApiToken: process.env.CONTENTFUL_PREVIEW_API_TOKEN,cacheDuration: 1000 * 60 * 60 * 24 // 1 day in ms
      }
    },'gatsby-plugin-postcss',`gatsby-plugin-sharp`,{
      resolve: `gatsby-plugin-manifest`,options: {
        start_url: `/`,icon: `src/images/favicon-32.png`,// This path is relative to the root of the site.
      }
    },'gatsby-transformer-sharp','gatsby-plugin-image','gatsby-plugin-emotion','gatsby-alias-imports','gatsby-plugin-react-helmet',{
      resolve: `gatsby-plugin-google-tagmanager`,options: {
        id: process.env.GOOGLE_TAG_MANAGER_ID,includeInDevelopment: false,},`gatsby-plugin-scroll-reveal`,// `gatsby-plugin-transition-link`
  ]
};

更新: Node v14.x 在我的本地环境中运行,并尝试在 Vercel 上选择 Node 版本 12。

许多警告消息都消失了,但我没有运气。

我认为奇怪的是我可以看到 developbuild 之间的内容节点差异。

enter image description here

enter image description here

如您所见,它在本地端运行 npm run dev 时创建了 128 个内容节点。

否则,它只在 Vercel 上创建了 100 个内容节点。

我不确定这是否是主要问题。

但基本上 gatsby 对内容节点有限制规则?

解决方法

为什么会这样?这似乎是 gatsby 或 vercel 问题。

提供的详细信息很难说。在我看来,Vercel 服务器似乎正面临某些 GraphQL 查询/产品/节点(警告)的超时响应,因此这可能是一种共同的罪恶感。

为了同时调试并尝试修复问题,考虑到项目在本地运行良好,我会尝试匹配环境,从设置相同的 Node 版本开始。这将确保您运行相同的依赖版本。

Vercel 允许您从后台或通过在 node 中的 engine 对象内设置 package.json 属性来配置 Node 版本。来自docs

node 文件的引擎内定义 package.json 属性 将覆盖在项目设置中所做的选择并打印 如果版本不匹配,则生成步骤警告。

为了找出您的 Deployment 使用的是哪个 Node.js 版本, 在构建命令中运行 node -v 或记录输出 process.version

所以添加:

"engines": { "node": "12.x" }

作为运行 12.x 命令时的 node -v 提示版本。

希望这能解决您的问题,但如果不能,它将帮助您更好地调试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-