使用 Kentico Kontent 时出现错误 运行 `gatsby build`

Error running `gatsby build` with Kentico Kontent

我有一个项目同时使用了两者 Gatsby and Kentico Kontent。我在我的本地机器上同时使用 gatsby developnpm run develop (Windows 10) 在开发中工作得很好。通常,输出如下所示:

$ npm run develop

success open and validate gatsby-configs - 0.169s
success load plugins - 0.426s
success onPreInit - 0.004s
success initialize cache - 0.007s
success copy gatsby files - 0.067s
success onPreBootstrap - 1.357s
success createSchemaCustomization - 0.545s
success source and transform nodes - 1.740s
success building schema - 0.358s
success createPages - 0.068s
success createPagesStatefully - 0.063s
success onPreExtractQueries - 0.002s
success update schema - 0.030s   
success extract queries from components - 0.177s
success write out requires - 0.027s
success write out redirect data - 0.007s
success onPostBootstrap - 0.003s
⠀
info bootstrap finished - 7.596 s
⠀
success run queries - 0.125s - 61/61 489.34/s
⠀
You can now view <project name> in the browser.
⠀
  http://localhost:8000/
⠀
View GraphiQL, an in-browser IDE, to explore your site's data and schema
⠀
  http://localhost:8000/___graphql
⠀
Note that the development build is not optimized.
To create a production build, use gatsby build
⠀
success Building development bundle - 3.319s

当我 运行 gatsby buildnpm run build 时,这总是失败,我看到以下 error/output:

$ npm run build

> <project name>@1.1.1 build C:\projects\<client>\<project name>
> gatsby build

success open and validate gatsby-configs - 0.155s
success load plugins - 0.435s
success onPreInit - 0.004s
success delete html and css files from previous builds - 0.019s
success initialize cache - 0.008s
success copy gatsby files - 0.076s
success onPreBootstrap - 0.028s

 ERROR #11321  PLUGIN

"@kentico/gatsby-source-kontent" threw an error while running the createSchemaCustomization lifecycle:



not finished createSchemaCustomization - 0.549s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <project name>@1.1.1 build: `gatsby build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <project name>@1.1.1 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\mattn\AppData\Roaming\npm-cache\_logs20-03-24T12_10_17_984Z-debug.log

查看建议的日志文件,我看到:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v12.16.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle <project name>@1.1.1~prebuild: <project name>@1.1.1
6 info lifecycle <project name>@1.1.1~build: <project name>@1.1.1
7 verbose lifecycle <project name>@1.1.1~build: unsafe-perm in lifecycle true
8 verbose lifecycle <project name>@1.1.1~build: PATH: <My Env Variables Path>
9 verbose lifecycle <project name>@1.1.1~build: CWD: C:\projects\<client>\<project name>
10 silly lifecycle <project name>@1.1.1~build: Args: [ '/d /s /c', 'gatsby build' ]
11 silly lifecycle <project name>@1.1.1~build: Returned: code: 1  signal: null
12 info lifecycle <project name>@1.1.1~build: Failed to exec build script
13 verbose stack Error: working-at-ridgeway@1.1.1 build: `gatsby build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:311:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:311:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid <project name>@1.1.1
15 verbose cwd C:\projects\<client>\<project name>
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "build"
18 verbose node v12.16.1
19 verbose npm  v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error <project name>@1.1.1 build: `gatsby build`
22 error Exit status 1
23 error Failed at the <project name>@1.1.1 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

是否有其他方法可以获取有关错误的详细信息,以便我找到解决方案?我已经尝试更新和安装 npm 包并 运行 在那个 gatsby 项目上安装 'clean',但似乎没有任何帮助。

这只是瞎猜,但是,我相信开发配置也将 different environment variables than production build (if using client-side javascript). Could you try to adjust env. variables according to gatsby's docu? What OS do you use? There are some significant differences in accessing .env variables 用于 Linux 和 Windows。

如果这不起作用,您能否在 GitHub repo 中创建一个问题并提供重现的步骤(或项目)?谢谢!

编辑:我也会尝试使用 Gatsby's env. variables plugin

该问题导致 version 6 of @kentico/gatsby-source-kontent 的新日志记录功能。

因此只需 运行 gatsby develop --verbosegatsby build --verbose 即可将日志从包中获取到终端。

Official information Implementation details