Tencent/cloudbase-framework

【gatsby应用部署】安装 gatsby-sharp插件失败, 导致构建不成功

Davont opened this issue · 5 comments

Bug 描述
腾讯云上部署gatsby app 构建失败。主要原因是安装插件 gatsby-plugin-sharpgatsby-transformer-sharp
这两个npm install, 会安装失败。
1

重现步骤
已在github上写好重现仓库testDemo。仓库基于官方gatsby模板

唯一的不同是在package.json 里面加上 上述两个插件

    "gatsby-plugin-sharp": "^2.6.36",
    "gatsby-transformer-sharp": "^2.5.15"

重现 bug 的步骤:
在腾讯云个人控制台 “我的应用” 里面部署模板
然后看到报错信息
3

1

预期的行为
本地 npm install -> npm run build 均成功。在腾讯云上理应也会部署成功。

主要错误日志

[2021-08-01 21:40:03] Sun Aug 01 2021 13:40:03 GMT+0000 (Coordinated Universal Time) 16.5 CloudBase Framework::info Website 插件会自动开启静态网页托管能力,需要当前环境为 [按量计费] 模式
[2021-08-01 21:40:03] Sun Aug 01 2021 13:40:03 GMT+0000 (Coordinated Universal Time) 16.5 CloudBase Framework::info Website 插件会部署应用资源到当前静态托管的 / 目录下
[2021-08-01 21:40:03] Sun Aug 01 2021 13:40:03 GMT+0000 (Coordinated Universal Time) 16.6 CloudBase Framework::info 🔨 build: gatsby...
[2021-08-01 21:40:03] Sun Aug 01 2021 13:40:03 GMT+0000 (Coordinated Universal Time) 16.6 CloudBase Framework::debug WebsitePlugin: build {
[2021-08-01 21:40:03]   outputPath: './public',
[2021-08-01 21:40:03]   cloudPath: '/',
[2021-08-01 21:40:03]   ignore: [ '.git', '.github', 'node_modules', 'cloudbaserc.js' ],
[2021-08-01 21:40:03]   commands: {
[2021-08-01 21:40:03]     install: 'npm install --prefer-offline --no-audit --progress=false'
[2021-08-01 21:40:03]   },
[2021-08-01 21:40:03]   buildCommand: 'npx gatsby build'
[2021-08-01 21:40:03] } 
[2021-08-01 21:40:04] Sun Aug 01 2021 13:40:03 GMT+0000 (Coordinated Universal Time) 16.7 CloudBase Framework::info running 'npm install --prefer-offline --no-audit --progress=false' 
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] > sharp@0.27.2 install /root/cloudbase-workspace/node_modules/sharp
[2021-08-01 21:40:42] > (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] > core-js@3.16.0 postinstall /root/cloudbase-workspace/node_modules/core-js
[2021-08-01 21:40:42] > node -e "try{require('./postinstall')}catch(e){}"
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] > core-js-pure@3.16.0 postinstall /root/cloudbase-workspace/node_modules/core-js-pure
[2021-08-01 21:40:42] > node -e "try{require('./postinstall')}catch(e){}"
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] > gatsby-telemetry@1.10.2 postinstall /root/cloudbase-workspace/node_modules/gatsby-telemetry
[2021-08-01 21:40:42] > node src/postinstall.js || true
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] 
[2021-08-01 21:40:42] > mozjpeg@7.1.0 postinstall /root/cloudbase-workspace/node_modules/mozjpeg
[2021-08-01 21:40:42] > node lib/install.js
[2021-08-01 21:40:42] 
[2021-08-01 21:40:44] Sun Aug 01 2021 13:40:44 GMT+0000 (Coordinated Universal Time) 57.0 CloudBase Framework::error  npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
[2021-08-01 21:40:44] npm WARN deprecated eslint-loader@2.2.1: This loader has been deprecated. Please use eslint-webpack-plugin
[2021-08-01 21:40:44] npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
[2021-08-01 21:40:44] npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
[2021-08-01 21:40:44] npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
[2021-08-01 21:40:44] npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
[2021-08-01 21:40:44] npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
[2021-08-01 21:40:44] npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
[2021-08-01 21:40:44] npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
[2021-08-01 21:40:44] npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
[2021-08-01 21:40:44] info sharp Using cached /root/.npm/_libvips/libvips-8.10.5-linuxmusl-x64.tar.br
[2021-08-01 21:40:44]   ⚠ spawn /root/cloudbase-workspace/node_modules/mozjpeg/vendor/cjpeg ENOENT
[2021-08-01 21:40:44]   ⚠ mozjpeg pre-build test failed
[2021-08-01 21:40:44]   ℹ compiling from source
[2021-08-01 21:40:44]   ✖ Error: Command failed: /bin/sh -c autoreconf -fiv
[2021-08-01 21:40:44] /bin/sh: autoreconf: not found
[2021-08-01 21:40:44] 
[2021-08-01 21:40:44] 
[2021-08-01 21:40:44]     at /root/cloudbase-workspace/node_modules/bin-build/node_modules/execa/index.js:231:11
[2021-08-01 21:40:44]     at runMicrotasks (<anonymous>)
[2021-08-01 21:40:44]     at processTicksAndRejections (internal/process/task_queues.js:95:5)
[2021-08-01 21:40:44]     at async Promise.all (index 0)
[2021-08-01 21:40:44] npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents):
[2021-08-01 21:40:44] npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
[2021-08-01 21:40:44] npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents):
[2021-08-01 21:40:44] npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
[2021-08-01 21:40:44] npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents):
[2021-08-01 21:40:44] npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
[2021-08-01 21:40:44] npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
[2021-08-01 21:40:44] npm WARN ts-node@9.1.1 requires a peer of typescript@>=2.7 but none is installed. You must install peer dependencies yourself.
[2021-08-01 21:40:44] npm WARN @n1ru4l/graphql-live-query@0.7.1 requires a peer of graphql@^15.4.0 but none is installed. You must install peer dependencies yourself.
[2021-08-01 21:40:44] 
[2021-08-01 21:40:44] npm ERR! code ELIFECYCLE
[2021-08-01 21:40:44] npm ERR! errno 1
[2021-08-01 21:40:44] npm ERR! mozjpeg@7.1.0 postinstall: `node lib/install.js`
[2021-08-01 21:40:44] npm ERR! Exit status 1
[2021-08-01 21:40:44] npm ERR! 
[2021-08-01 21:40:44] npm ERR! Failed at the mozjpeg@7.1.0 postinstall script.
[2021-08-01 21:40:44] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[2021-08-01 21:40:44] 
[2021-08-01 21:40:44] npm ERR! A complete log of this run can be found in:
[2021-08-01 21:40:44] npm ERR!     /root/.npm/_logs/2021-08-01T13_40_44_066Z-debug.log
[2021-08-01 21:40:44] 
[2021-08-01 21:40:44] Sun Aug 01 2021 13:40:44 GMT+0000 (Coordinated Universal Time) 57.0 CloudBase Framework::info 部署日志: '/root/cloudbase-framework/logs/2021-08-01_13-39-47.log' 
[2021-08-01 21:40:44] [Pipeline] }
[2021-08-01 21:40:44] [Pipeline] // stage
[2021-08-01 21:40:44] [Pipeline] stage
[2021-08-01 21:40:44] [Pipeline] { (Declarative: Post Actions)
[2021-08-01 21:40:44] [Pipeline] sh
[2021-08-01 21:40:45] [Pipeline] }
[2021-08-01 21:40:45] [Pipeline] // stage
[2021-08-01 21:40:45] [Pipeline] }
[2021-08-01 21:40:45] $ docker stop --time=1 7ceebb5e9ebcf5337cf7ae6ec8f1c639f8e6f58ecc4094c677fded5e0c9b6a1c
[2021-08-01 21:40:46] $ docker rm -f 7ceebb5e9ebcf5337cf7ae6ec8f1c639f8e6f58ecc4094c677fded5e0c9b6a1c
[2021-08-01 21:40:47] [Pipeline] // withDockerContainer
[2021-08-01 21:40:47] [Pipeline] }
[2021-08-01 21:40:47] [Pipeline] // node
[2021-08-01 21:40:47] [Pipeline] End of Pipeline
[2021-08-01 21:40:47] ERROR: script returned exit code 1
[2021-08-01 21:40:47] Finished: FAILURE

可以根据错误信息来看下

sharp Using cached /root/.npm/_libvips/libvips-8.10.5-linuxmusl-x64.tar.br
[2021-08-01 21:40:44] ⚠ spawn /root/cloudbase-workspace/node_modules/mozjpeg/vendor/cjpeg ENOENT
[2021-08-01 21:40:44] ⚠ mozjpeg pre-build test failed
[2021-08-01 21:40:44] ℹ compiling from source

libvipssharp 包的必须组件,在机器上如果没有 libvips,会尝试自己编译,可能缺少编译环境相关的组件,可以检查一下 libvips 安装部分的文档

上方错误信息里关键的信息可能是 autoreconf: not found

谢谢回复,在网上确实搜索到一些信息:
https://stackoverflow.com/questions/64927442/gatsby-build-failing-on-mozjpeg
但由于这个部署是在腾讯云,感觉应该是机器上缺少一些配置。

我这边可以直接操作机器上的配置吗?对于开发者来说我应该不感知的

谢谢回复,在网上确实搜索到一些信息:
https://stackoverflow.com/questions/64927442/gatsby-build-failing-on-mozjpeg
但由于这个部署是在腾讯云,感觉应该是机器上缺少一些配置。

我这边可以直接操作机器上的配置吗?对于开发者来说我应该不感知的

可以考虑 Docker Image 的方式部署,这样环境自己可控。

谢谢回复,在网上确实搜索到一些信息:
https://stackoverflow.com/questions/64927442/gatsby-build-failing-on-mozjpeg
但由于这个部署是在腾讯云,感觉应该是机器上缺少一些配置。
我这边可以直接操作机器上的配置吗?对于开发者来说我应该不感知的

可以考虑 Docker Image 的方式部署,这样环境自己可控。

嗯嗯 我已经用其他方法部署上去了。
不过这个npm插件 安装失败 的 问题,在这边可以关注一下