2021-11-28に投稿

yarn 時に gifsicle で gifsicle pre-build test failed エラー

読了目安:10分

数日前から yarn 時に gifsicle で gifsicle pre-build test failed エラーが出るようになってしまったので対処します。

あれこれ試しましたが、結論から言うと imagemin-gifsicle が依存している gifsicle5.0.0 だとダメなので、 resolution5.2.1 を指定すると良さそうです。

現象

    "devDependencies": {

        // 略

        "gulp-imagemin": "^7.1.0",
        "imagemin-mozjpeg": "^9.0.0",
        "imagemin-pngquant": "^9.0.2",
        "imagemin-gifsicle": "^7.0.0",
        "imagemin-svgo": "^9.0.0",

        // 略

    }

imagemin-gifsicle を使用しているプロジェクトで yarn したところ、以下のエラーで失敗するようになってしまいました。

warning Error running install script for optional dependency: "PATH\\TO\\PROJECT\\node_modules\\gifsicle: Command failed.
Exit code: 1
Command: node lib/install.js
Arguments:
Directory: PATH\\TO\\PROJECT\\node_modules\\gifsicle
Output:
Response code 404 (Not Found)
gifsicle pre-build test failed
compiling from source
Error: Command failed: C:\\WINDOWS\\system32\\cmd.exe /s /c \"autoreconf -ivf\"
'autoreconf' �́A�����R�}���h�܂��͊O���R�}���h�A
����\\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF������Ă��܂���B


    at PATH\\TO\\PROJECT\\node_modules\\bin-build\\node_modules\\execa\\index.js:231:11
success Saved lockfile.

バージョンを上げても直後は特に問題なかったような気はするのですが、逐一キャッシュを削除したりしているわけではないので不明。

仕方ないので、色々ググりながら対応してみます。

対処 (失敗したものたち)

gisicle を足す

    "devDependencies": {
        // 略
        "gulp-imagemin": "^7.1.0",
        "imagemin-mozjpeg": "^9.0.0",
        "imagemin-pngquant": "^9.0.2",
        "imagemin-gifsicle": "^7.0.0",
        "gifsicle": "6.1.0",            // 追加
        "imagemin-svgo": "^9.0.0",
        // 略
    }

変わらず。

逆にいっそ gulp-imagemin 以外全て削除

    "devDependencies": {
        // 略
        "gulp-imagemin": "^7.1.0",
        // 略
    }

変わらず。

コマンドプロンプトを管理者実行

gifsicle ありの状態で cmd.exe を管理者として実行→変わらず。

キャッシュ削除

> yarn cache clean
yarn cache v1.22.11
success Cleared cache.
Done in 450.56s.

変わらず。

hosts に Github 関係の名前解決を書き込む

>ping raw.githubusercontent.com

raw.githubusercontent.com [185.199.108.133]に ping を送信しています 32 バイトのデータ:
185.199.108.133 からの応答: バイト数 =32 時間 =5ms TTL=58
185.199.108.133 からの応答: バイト数 =32 時間 =5ms TTL=58

185.199.108.133 の ping 統計:
    パケット数: 送信 = 2、受信 = 2、損失 = 0 (0% の損失)、
ラウンド トリップの概算時間 (ミリ秒):
    最小 = 5ms、最大 = 5ms、平均 = 5ms

元々 raw.githubusercontent.com に ping はできていましたが、 hosts に次のように追記してみます。

52.74.223.119     github.com
192.30.253.119    gist.github.com
54.169.195.247    api.github.com
185.199.111.153   assets-cdn.github.com
151.101.76.133    raw.githubusercontent.com
151.101.76.133    gist.githubusercontent.com
151.101.76.133    cloud.githubusercontent.com
151.101.76.133    camo.githubusercontent.com
151.101.76.133    avatars0.githubusercontent.com
151.101.76.133    avatars1.githubusercontent.com
151.101.76.133    avatars2.githubusercontent.com
151.101.76.133    avatars3.githubusercontent.com
151.101.76.133    avatars4.githubusercontent.com
151.101.76.133    avatars5.githubusercontent.com
151.101.76.133    avatars6.githubusercontent.com
151.101.76.133    avatars7.githubusercontent.com
151.101.76.133    avatars8.githubusercontent.com

変わらず。

なお、ここまで次の issue にあった対処法。

ネットワークを変更

違う場所に出かけて、ゲートウェイを変更してみました。

が、変わらず。

最小限構成で実験する

長丁場になりそうだったので最小限構成の package.json を作成して検証を続行。

{
  "name": "tmp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "imagemin-gifsicle": "^7.0.0"
  }
}

これでyarn。変わらず。

ちなみに yarn.lock の中身は次のような感じ。

gifsicle@^5.0.0:
  version "5.3.0"
  resolved "https://registry.yarnpkg.com/gifsicle/-/gifsicle-5.3.0.tgz#499713c6f1e89ebbc3630da3a74fdb4697913b4e"
  integrity sha512-FJTpgdj1Ow/FITB7SVza5HlzXa+/lqEY0tHQazAJbuAdvyJtkH4wIdsR2K414oaTwRXHFLLF+tYbipj+OpYg+Q==
  dependencies:
    bin-build "^3.0.0"
    bin-wrapper "^4.0.0"
    execa "^5.0.0"

imagemin-gifsicle@^7.0.0:
  version "7.0.0"
  resolved "https://registry.yarnpkg.com/imagemin-gifsicle/-/imagemin-gifsicle-7.0.0.tgz#1a7ab136a144c4678657ba3b6c412f80805d26b0"
  integrity sha512-LaP38xhxAwS3W8PFh4y5iQ6feoTSF+dTAXFRUEYQWYst6Xd+9L/iPk34QGgK/VO/objmIlmq9TStGfVY2IcHIA==
  dependencies:
    execa "^1.0.0"
    gifsicle "^5.0.0"
    is-gif "^3.0.0"

imagemin-gifsicle が依存している gifsicle のバージョンが悪いのではないか、と思い resolutions を追加することにしました。

resolutions を追加

{
  "name": "tmp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "imagemin-gifsicle": "^7.0.0"
  },
  "resolutions": {
    "gifsicle": "^6.1.0"
  }
}

すると、 yarn は通りました。

しかし、 6系 は "Use native ESM" なので require を使用している現環境での使用は不可です。惜しい。

resolutions の指定を 5.3.0 にする

[email protected], gifsicle@^5.0.0:
  version "6.1.0"
  resolved "https://registry.yarnpkg.com/gifsicle/-/gifsicle-6.1.0.tgz#16194fe7d9420a539709eb065e7245eaf74de5a7"
  integrity sha512-tmnKbW2UQzoc/FTg2dq98sUaoGM1/CRQP+HtyeIMNLDlB8ijZbX7TKBCc2s5YJ8oXUZIxdqXH2rKXnCB0/Hg3w==
  dependencies:
    bin-build "^3.0.0"
    bin-wrapper "^4.0.0"
    execa "^5.1.1"

gifsicle - npmを確認したところ、11/26現在で 6.1.0 と並んで "3 days ago" となっている 5系 最新の 5.3.0 があることが判明。

{
  "name": "tmp",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "imagemin-gifsicle": "^7.0.0"
  },
  "resolutions": {
    "gifsicle": "^5.3.0"
  }
}

しかしNG。

yep, this repo's 5.3.0 tag is missing, that makes the downloading process of bin-wrapper failed.

5.3.0 is error · Issue #134 · imagemin/gifsicle-bin · GitHub

タグ付けをミスって生まれてしまったバージョンらしいので、これは使えないとのこと。なんて紛らわしい……。

resolutions の指定を 5.2.1 にする

{
    "name": "tmp",
    "version": "1.0.0",
    "main": "index.js",
    "license": "MIT",
    "devDependencies": {
      "imagemin-gifsicle": "^7.0.0"
    },
    "resolutions": {
      "gifsicle": "5.2.1"
    }
}

^5.2.1 とキャレットを付けると 5.2.1 <= version < 6.0.0 となってしまい、 5.3.0 に上がってしまうので 5.2.1 とキャレットを外して指定します。

[email protected], gifsicle@^5.0.0:
  version "5.2.1"
  resolved "https://registry.yarnpkg.com/gifsicle/-/gifsicle-5.2.1.tgz#efadab266a493ef0b4178e34597493349937369e"
  integrity sha512-9ewIQQCAnSmkU2DhuWafd1DdsgzAkKqIWnY+023xBLSiK9Az2TDUozWQW+SyRQgFMclbe6RQldUk/49TRO3Aqw==
  dependencies:
    bin-build "^3.0.0"
    bin-wrapper "^4.0.0"
    execa "^5.0.0"

imagemin-gifsicle@^7.0.0:
  version "7.0.0"
  resolved "https://registry.yarnpkg.com/imagemin-gifsicle/-/imagemin-gifsicle-7.0.0.tgz#1a7ab136a144c4678657ba3b6c412f80805d26b0"
  integrity sha512-LaP38xhxAwS3W8PFh4y5iQ6feoTSF+dTAXFRUEYQWYst6Xd+9L/iPk34QGgK/VO/objmIlmq9TStGfVY2IcHIA==
  dependencies:
    execa "^1.0.0"
    gifsicle "^5.0.0"
    is-gif "^3.0.0"

これでようやく通りました。処理も無事にできることを確認。

……思ったよりも手間取りました。

参考

gifsicle

package.json

Originally published at labor.ewigleere.net
ツイッターでシェア
みんなに共有、忘れないようにメモ

arm-band

フロントエンド・バックエンド・サーバエンジニア。LAMPやNodeからWP、Gulpを使ってejs,Scss,JSのコーディングまで一通り。たまにRasPiで遊んだり、趣味で開発したり。

Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。

また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!

有料記事を販売できるようになりました!

こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?

コメント