0
0

`Error: spawn node-gyp ENOENT`の解消方法

Posted at

エラー内容

docker build時に出たエラーです。

Error: spawn node-gyp ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node-gyp',
  path: 'node-gyp',
  spawnargs: [ 'rebuild' ]
}

Node.js v18.18.1

node-gypをグローバルインストールすれば解消できる」という事例もブログなどで見かけましたが、これでは解消せず・・・

原因

Dockerfile内のnodeイメージのバージョンだったようです。

node:18からnode:18.17に変更することで解消できました。マイナーバージョンまで指定するところがキモです。

まとめ

JavaScript周りのライブラリは結構Node.jsのバージョンに依存していることがあるので、メジャーバージョンのみの指定やlatestを使用するのはビルドプロセスの安定稼働を考えるとちょっと不安です。

経験上、マイナーバージョンまで固定するのが良いです(パッチバージョンまで固定するのはやり過ぎ感がある、かつ軽微なバグ修正やセキュリティパッチが入る可能性を考えると、ここは緩く受け入れた方が良さそう)。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0