Gatsby构建失败,出现mozjpeg错误

4

从昨天开始,我无法将我的 Gatsby 网站部署到我们的服务器上,构建过程报告了 mozjpeg 库的错误。有人遇到过这个错误吗?

我尝试过:

  • 锁定 gatsby-cli 版本
  • 安装 automake Linux 包
  • 安装 libtools Linux 包
  • 解锁 yarn.lock 文件
  • 在没有锁定文件的情况下安装依赖项

但是似乎什么都没用,错误信息如下:

error /node_modules/mozjpeg: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: /node_modules/mozjpeg
Output:
 spawn /node_modules/mozjpeg/vendor/cjpeg ENOENT
 mozjpeg pre-build test failed
 compiling from source
 Error: Command failed: /bin/sh -c ./configure --enable-static --disable-shared --disable-dependency-tracking --with-jpeg8 --prefix="/node_modules/mozjpeg/vendor" --bindir="/node_modules/mozjpeg/vendor" --libdir="/node_modules/mozjpeg/vendor"

操作系统 Ubuntu 16.04.6 节点版本 12.14 Gatsby 版本 2.19.7

3个回答

14

1
所有问题都得到了解决!我之前访问了所有的链接,但缓存不见了。谢谢! - Mario Nikolaus

1
使用docker镜像image: "node:lts-alpine"部署到GitLab页面时,遇到了相同的问题。由于yarn:install无法构建mozjpeg,因此失败了。

错误/builds/my_project/gatsby/node_modules/mozjpeg:命令失败。

为了解决这个问题,请将以下行添加到.gitlab-ci.yml中。
before_script:
   - apk add make nasm autoconf automake libtool dpkg pkgconfig libpng libpng-dev g++

预期结果

[4/4] Building fresh packages...
Done in 170.33s.
Saving cache for successful job
00:27
Creating cache master-1...
node_modules/: found 82747 matching files and directories 
WARNING: .cache/: no matching files                
WARNING: public/: no matching files                
Uploading cache.zip to https://storage.googleapis.com/gitlab-com-runners-cache/project/...
Created cache
Cleaning up file based variables
00:01
Job succeeded

实际结果

[4/4] Building fresh packages...
error /builds/my_project/gatsby/node_modules/mozjpeg: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments: 
Directory: /builds/my_project/gatsby/node_modules/mozjpeg
Output:
 spawn /builds/my_project/gatsby/node_modules/mozjpeg/vendor/cjpeg ENOENT
   mozjpeg pre-build test failed
   compiling from source
   Error: Command failed: /bin/sh -c autoreconf -fiv
/bin/sh: autoreconf: not found
    at /builds/my_project/gatsby/node_modules/bin-build/node_modules/execa/index.js:231:11
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 0)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

环境

来自以下镜像的操作系统信息:image: "node:lts-alpine"

package.json 信息:

  npmPackages:
    gatsby: ^2.31.1 => 2.31.1
    gatsby-image: ^2.10.0 => 2.10.0
    gatsby-plugin-manifest: ^2.11.0 => 2.11.0
    gatsby-plugin-material-ui: ^2.1.10 => 2.1.10
    gatsby-plugin-offline: ^3.9.0 => 3.9.0
    gatsby-plugin-react-helmet: ^3.9 => 3.9.0
    gatsby-plugin-sharp: ^2.13.4 => 2.13.4
    gatsby-source-filesystem: ^2.10.0 => 2.10.0
    gatsby-theme-firebase: ^1.0.10 => 1.0.10
    gatsby-transformer-sharp: ^2.11.0 => 2.11.0
  npmGlobalPackages:
    gatsby-cli: 2.17.0

请注意,需要使用make命令,如果Docker镜像中没有安装,则必须先进行安装。 - Piskunow

-1

我在Dockerfile中遇到了与Alpine相同的问题。结果发现它需要的是通常需要从源代码构建的所有内容。 Alpine有一个名为alpine-apk的软件包,我将其添加到了Dockerfile中。这解决了我使用mozjpeg时遇到的所有后续问题。我知道原始帖子的作者没有运行Alpine,但我希望这篇文章能够发布到某个地方,以便另一个遇到此问题的人可以看到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接