コツコツと

[Netlify]デプロイ時に「The engine "node" is incompatible with this module.」エラーが発生する

November 17, 2021

Gatsby 製ブログの node モジュール一式を update し、Netlify にデプロイしたところ次のエラーが発生しました。

error gatsby@4.2.0: The engine "node" is incompatible with this module. 
Expected version ">=14.15.0". Got "12.18.0"

このエラーを解消するには、node のバージョンを上げる必要があります。
ドキュメントを確認したところ、Netlify では、.node-version ファイルにより、node のバージョンを指定できるとのことでした。

次の.node-version ファイルを作成して、プロジェクトのルートディレクトリに格納して再デプロイしたところエラーは解消されました。

// .node-versionファイル
// この設定で、nodeのversion 14.x のlatestがインストールされる
14

下記は、デプロイ時の log を抜粋したものです。
.node-version で指定したバージョンの node がインストールされていることがわかります。

Started restoring cached node version
Finished restoring cached node version
Attempting node version '14' from .node-version
Downloading and installing node v14.18.1...
Downloading https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-x64.tar.xz...
Computing checksum with sha256sum
Checksums matched!
Now using node v14.18.1 (npm v6.14.15)
Started restoring cached build plugins
Finished restoring cached build plugins
...

© 2020 jiri3