0

我正在使用 CodeSandbox 制作 Gatsby 应用程序,并且我正在尝试将 Prismic 用于后端。我确定它设置得很好,并安装gatsby-source-prismic到我的项目中。但是,当我将它添加到我的配置文件并重新启动项目时,它会抛出一个错误,提示“无效的插件选项”。这是我的插件文件中的内容:

{
  resolve: `gatsby-source-prismic`,
  options: {
    repositoryName: `firstprism`,
    accessToken: `XXX`
  },
},

这是堆栈:

 ERROR

gatsby-source-prismic - 无效的插件选项

错误

需要一个类型record<string,object>schemas但已接收的值undefined

错误:

  • index.cjs:650 新的 StructError [沙盒]/[superstruct]/lib/index.cjs:650:19

  • index.cjs:707 Function.Struct.assert [沙盒]/[superstruct]/lib/index.cjs:707:13

  • index.cjs:679 结构 [沙盒]/[超结构]/lib/index.cjs:679:19

  • gatsby-node.js:74 validatePluginOptions [沙盒]/[gatsby-source-prismic]/dist/gatsby-node.js:74:50

  • gatsby-node.js:1042 [沙盒]/[gatsby-source-prismic]/dist/gatsby-node.js:1042:25

  • 生成器.next

  • gatsby-node.js:52 [沙盒]/[gatsby-source-prismic]/dist/gatsby-node.js:52:71

  • 新的承诺

  • gatsby-node.js:48 __awaiter [沙盒]/[gatsby-source-prismic]/dist/gatsby-node.js:48:12

  • gatsby-node.js:1029 Object.sourceNodes [沙盒]/[gatsby-source-prismic]/dist/gatsby-node.js:1029:55

  • api-runner-node.js:256 runAPI [沙盒]/[gatsby]/dist/utils/api-runner-node.js:256:37

  • api-runner-node.js:375 解析 [沙盒]/[gatsby]/dist/utils/api-runner-node.js:375:15

  • debuggability.js:384 Promise._execute [沙盒]/[bluebird]/js/release/debuggability.js:384:9

  • promise.js:518 Promise._resolveFromExecutor [沙盒]/[bluebird]/js/release/promise.js:518:18

  • promise.js:103 新的 Promise [沙盒]/[bluebird]/js/release/promise.js:103:10

  • api-runner-node.js:374 Promise.mapSeries.plugin [沙盒]/[gatsby]/dist/utils/api-runner-node.js:374:12

4

2 回答 2

3

我刚遇到这个问题。看来现在需要提供 JSON 模式,如文档中所述:https ://github.com/angeloashmore/gatsby-source-prismic#providing-json-schemas

编辑:另请参阅https://github.com/angeloashmore/gatsby-source-prismic/blob/master/docs/migrating-from-v2-to-v3.md

于 2020-04-18T22:46:31.383 回答
0

就像这样

options: {
        repositoryName: 'your-repository-name',
        accessToken: `${process.env.API_KEY}`,
        linkResolver: ({ node, key, value }) => post => `/${post.uid}`,
        schemas: {
          page: require("./src/schemas/page.json"),
        },
      },

而不是现在

options: {
        repositoryName: `your-repository-name`,
        accessToken: `${process.env.API_KEY}`,
        linkResolver: ({ node, key, value }) => post => `/${post.uid}`,
        page: require("./src/schemas/page.json"),
      },
于 2020-09-30T16:53:17.253 回答