【发布时间】:2020-06-28 03:50:32
【问题描述】:
我决定建立自己的博客并选择 EmaSuriano 的 gatsby-starter-mate 作为我的 Gatsby Starter(我对 Gatsby 和 Contentful 完全陌生!)
我按照指示做了所有事情,设置我的环境,设置 Contentful 空间并登录 Contentful 等等。
目前,我在 Ubuntu 18.04 和
$ gatsby --version
Gatsby CLI version: 2.10.10
Gatsby version: 2.19.45
$ contentful --version
1.2.14
下面的一切都成功了,没有问题
$ gatsby new mate-portfolio https://github.com/EmaSuriano/gatsby-starter-mate
$ yarn setup
但是当我
$ yarn start
然后输入 localhost:8000 我得到 Failed to Compile 页面,其中包含大量错误。
我参考了这个https://github.com/gatsbyjs/gatsby/issues/16455 问题来解决我的问题并尝试了那里可用的解决方案,例如
- 删除fragments.js文件中的代码
- 删除.cache文件夹
- 将虚拟图片添加到我的空间
我还安装了$ npm install --save gatsby-source-contentful。 $ yarn add gatsby 和 $ yarn global add contentful-cli 也一样。
但它们都不起作用。以下是我在$ yarn start 时在 localhost:8000 上显示的错误。
谁能帮我解决这个问题?非常感谢!
There was an error in your GraphQL query:
Unknown type "ContentfulFixed".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulFixed".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulFluid".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulFluid".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulResolutions".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulResolutions".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulResolutions".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulSizes".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulSizes".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Unknown type "ContentfulSizes".
File: /blog/node_modules/gatsby-source-contentful/src/fragments.js
There was an error in your GraphQL query:
Cannot query field "contentfulAbout" on type "Query".
If you don't expect "contentfulAbout" to exist on the type "Query" it is most likely a typo.
However, if you expect "contentfulAbout" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "contentfulAbout" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/components/Helmet.js
There was an error in your GraphQL query:
Cannot query field "contentfulAbout" on type "Query".
If you don't expect "contentfulAbout" to exist on the type "Query" it is most likely a typo.
However, if you expect "contentfulAbout" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "contentfulAbout" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/components/Footer.js
There was an error in your GraphQL query:
Cannot query field "contentfulAbout" on type "Query".
If you don't expect "contentfulAbout" to exist on the type "Query" it is most likely a typo.
However, if you expect "contentfulAbout" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "contentfulAbout" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/Landing.js
There was an error in your GraphQL query:
Cannot query field "siteMetadata" on type "Site".
If you don't expect "siteMetadata" to exist on the type "Site" it is most likely a typo.
However, if you expect "siteMetadata" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "siteMetadata" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Site":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/Landing.js
There was an error in your GraphQL query:
Cannot query field "contentfulAbout" on type "Query".
If you don't expect "contentfulAbout" to exist on the type "Query" it is most likely a typo.
However, if you expect "contentfulAbout" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "contentfulAbout" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/Projects.js
There was an error in your GraphQL query:
Cannot query field "siteMetadata" on type "Site".
If you don't expect "siteMetadata" to exist on the type "Site" it is most likely a typo.
However, if you expect "siteMetadata" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "siteMetadata" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Site":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/Writing.js
There was an error in your GraphQL query:
Cannot query field "allMediumPost" on type "Query".
If you don't expect "allMediumPost" to exist on the type "Query" it is most likely a typo.
However, if you expect "allMediumPost" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "allMediumPost" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/Writing.js
There was an error in your GraphQL query:
Cannot query field "mediumUser" on type "Query".
If you don't expect "mediumUser" to exist on the type "Query" it is most likely a typo.
However, if you expect "mediumUser" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "mediumUser" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/Writing.js
There was an error in your GraphQL query:
Cannot query field "contentfulAbout" on type "Query".
If you don't expect "contentfulAbout" to exist on the type "Query" it is most likely a typo.
However, if you expect "contentfulAbout" to exist there are a couple of solutions to common problems:
- If you added a new data source and/or changed something inside gatsby-node.js/gatsby-config.js, please try a restart of your development server
- The field might be accessible in another subfield, please try your query in GraphiQL and use the GraphiQL explorer to see which fields you can query and what shape they have
- You want to optionally use your field "contentfulAbout" and right now it is not used anywhere. Therefore Gatsby can't infer the type and add it to the GraphQL schema. A quick fix is to add a least one entry with that field ("dummy content")
It is recommended to explicitly type your GraphQL schema if you want to use optional fields. This way you don't have to add the mentioned "dummy content". Visit our docs to learn how you can define the schema for "Query":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: /blog/src/sections/About.js
【问题讨论】:
-
更新:我设法删除了
Unknown type "ContentfulFixed"、Unknown type "ContentfulFluid"、Unknown type "ContentfulResolutions"和Unknown type "ContentfulSizes"的 GraphQL 查询错误 通过删除.../src/fragments.js文件 但是查询字段错误,例如下面的"contentfulAbout"和"allMediumPost"无法解决:'( -
您是否向 Contentful 添加了中型用户和关于文本?该错误是由 GraphQL 触发的,因为它试图从 Contentful 中提取此数据,但找不到。
-
您的
.env文件中是否存在有效的ACCESS_TOKEN和SPACE_ID? -
是的,正如@RobinMétral 提到的,确保您的所有内容模型都至少包含该模型的一个内容。
标签: javascript node.js graphql gatsby contentful