我正在设置一个盖茨比博客,并在gatsby-config.js中对siteMetadata进行了更改。
siteMetadata: {
title: `my blog`,
description: `A Blog starter`,
author: `dan`,
authorTagline: 'Learning',
social: {
twitter: `asdfg`,
},我还删除了content文件夹中的所有内容,以便添加自己的博客文章。到目前为止,content是一个空文件夹。
现在,在gatsby develop上,我发现了错误。我不精通gatsby和graphql,我想尽快建立这个博客。以下是整个错误列表:
myPC@myPC:~/Downloads/gatsby-blog$ gatsby develop
success open and validate gatsby-configs - 0.046s
success load plugins - 1.021s
warn The Google Analytics plugin requires a tracking ID. Did you mean to add it?
success onPreInit - 0.026s
info One or more of your plugins have changed since the last time you ran Gatsby. As
a precaution, we're deleting your site's cache to ensure there's no stale data.
success initialize cache - 0.022s
success copy gatsby files - 0.037s
success onPreBootstrap - 0.020s
success createSchemaCustomization - 0.069s
success source and transform nodes - 0.131s
success building schema - 0.375s
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Expected type MarkdownRemarkFieldsEnum, found frontmatter___date.
File: gatsby-node.js:7:10
ERROR #85923 GRAPHQL
There was an error in your GraphQL query:
Cannot query field "fields" on type "MarkdownRemark".
If you don't expect "fields" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "fields" 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 "fields" 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 "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: gatsby-node.js:7:10
ERROR #85923 GRAPHQL
There was an error in your GraphQL query:
Cannot query field "frontmatter" on type "MarkdownRemark".
If you don't expect "frontmatter" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "frontmatter" 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 "frontmatter" 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 "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: gatsby-node.js:7:10
[
GraphQLError: Expected type MarkdownRemarkFieldsEnum, found frontmatter___date.
at Object.EnumValue (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/rules/ValuesOfCorrectType.js:112:29)
at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:324:29)
at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:375:25)
at visit (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:242:26)
at validate (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/validate.js:73:24)
at GraphQLRunner.validate (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:84:44)
at GraphQLRunner.query (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:149:25)
at /home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:33:37
at /home/myPC/Downloads/gatsby-blog/gatsby-node.js:10:7
at new Promise (<anonymous>)
at Object.exports.createPages (/home/myPC/Downloads/gatsby-blog/gatsby-node.js:7:10)
at runAPI (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
at Promise.catch.decorateEvent.pluginName (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
at Promise._execute (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:103:10) {
locations: [ [Object] ]
},
GraphQLError: Cannot query field "fields" on type "MarkdownRemark".
at Object.Field (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)
at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:324:29)
at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:375:25)
at visit (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:242:26)
at validate (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/validate.js:73:24)
at GraphQLRunner.validate (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:84:44)
at GraphQLRunner.query (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:149:25)
at /home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:33:37
at /home/myPC/Downloads/gatsby-blog/gatsby-node.js:10:7
at new Promise (<anonymous>)
at Object.exports.createPages (/home/myPC/Downloads/gatsby-blog/gatsby-node.js:7:10)
at runAPI (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
at Promise.catch.decorateEvent.pluginName (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
at Promise._execute (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:103:10) {
locations: [ [Object] ]
},
GraphQLError: Cannot query field "frontmatter" on type "MarkdownRemark".
at Object.Field (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:53:31)
at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:324:29)
at Object.enter (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:375:25)
at visit (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/language/visitor.js:242:26)
at validate (/home/myPC/Downloads/gatsby-blog/node_modules/graphql/validation/validate.js:73:24)
at GraphQLRunner.validate (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:84:44)
at GraphQLRunner.query (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/query/graphql-runner.js:149:25)
at /home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/bootstrap/create-graphql-runner.js:33:37
at /home/myPC/Downloads/gatsby-blog/gatsby-node.js:10:7
at new Promise (<anonymous>)
at Object.exports.createPages (/home/myPC/Downloads/gatsby-blog/gatsby-node.js:7:10)
at runAPI (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:256:37)
at Promise.catch.decorateEvent.pluginName (/home/myPC/Downloads/gatsby-blog/node_modules/gatsby/dist/utils/api-runner-node.js:375:15)
at Promise._execute (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (/home/myPC/Downloads/gatsby-blog/node_modules/bluebird/js/release/promise.js:103:10) {
locations: [ [Object] ]
}
]
ERROR #11321 PLUGIN
"gatsby-node.js" threw an error while running the createPages lifecycle:
Cannot read property 'allMarkdownRemark' of undefined
35 |
36 | // Create blog posts pages.
> 37 | const posts = result.data.allMarkdownRemark.edges;
| ^
38 |
39 | posts.forEach((post, index) => {
40 | const previous =
File: gatsby-node.js:37:35
TypeError: Cannot read property 'allMarkdownRemark' of undefined
- gatsby-node.js:37
/home/myPC/Downloads/gatsby-blog/gatsby-node.js:37:35
- From previous event:
- api-runner-node.js:258 runAPI
[gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:258:22
- api-runner-node.js:375 Promise.catch.decorateEvent.pluginName
[gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:375:15
- From previous event:
- api-runner-node.js:374
[gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:374:12
- timers.js:456 processImmediate
internal/timers.js:456:21
- From previous event:
- api-runner-node.js:368
[gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:368:11
- From previous event:
- api-runner-node.js:275 module.exports
[gatsby-blog]/[gatsby]/dist/utils/api-runner-node.js:275:12
- index.js:421 module.exports
[gatsby-blog]/[gatsby]/dist/bootstrap/index.js:421:9
- develop-process.js:433 async module.exports
[gatsby-blog]/[gatsby]/dist/commands/develop-process.js:433:7
failed createPages - 0.145s
success createPagesStatefully - 0.094s
success onPreExtractQueries - 0.003s
success update schema - 0.045s
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Expected type MarkdownRemarkFieldsEnum, found frontmatter___date.
File: src/pages/index.js:49:40
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Unknown argument "fields" on field "markdownRemark" of type "Query".
GraphQL request:9:20
8 | }
9 | markdownRemark(fields: { slug: { eq: $slug } }) {
| ^
10 | id
File: src/templates/blog-post.js:77:20
ERROR #85923 GRAPHQL
There was an error in your GraphQL query:
Cannot query field "fields" on type "MarkdownRemark".
If you don't expect "fields" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "fields" 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 "fields" 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 "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: src/templates/blog-post.js:81:7
ERROR #85923 GRAPHQL
There was an error in your GraphQL query:
Cannot query field "frontmatter" on type "MarkdownRemark".
If you don't expect "frontmatter" to exist on the type "MarkdownRemark" it is most likely a typo.
However, if you expect "frontmatter" 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 "frontmatter" 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 "MarkdownRemark":
https://www.gatsbyjs.org/docs/schema-customization/#creating-type-definitions
File: src/templates/blog-post.js:86:7
failed extract queries from components - 0.476s
success write out requires - 0.046s
success write out redirect data - 0.013s
success Build manifest and related icons - 0.184s
success onPostBootstrap - 0.202s
⠀
info bootstrap finished - 5.922s
⠀
success run static queries - 0.058s - 3/3 51.39/s
success run page queries - 0.024s - 4/4 167.48/s
warn Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
ERROR #98123 WEBPACK
Generating development JavaScript bundle failed
/home/myPC/Downloads/gatsby-blog/src/pages/index.js
49:40 error Expected type MarkdownRemarkFieldsEnum, found frontmatter___date graphql/template-strings
✖ 1 problem (1 error, 0 warnings)
File: src/pages/index.js
failed Building development bundle - 4.692s帮我解决这个问题。谢谢!
发布于 2021-03-03 17:44:02
因为删除了/content文件夹,所以所有指向该内容的引用和查询都会破坏代码,因为无法获取所查询的内容。
您可以在gatsby-node.js和blog-post.js中引用缺失的内容。
解决办法:
blog-post.js中)。这是冗长的,不推荐的,因为您将需要取消评论/恢复它,一旦您添加新的内容。P.S:对内容的查询引用可能类似于:
allMarkdownRemark(
sort: { fields: [frontmatter___date], order: DESC }
limit: 1000
) {
edges {
node {
fields {
slug
}
frontmatter {
title
}
}
}
}
}
`https://stackoverflow.com/questions/66460388
复制相似问题