Cloudflare Pages Error: Exit with error code: 126 When Specified Node.js Version Is Not Available

Tadashi Shigeoka ·  Sat, October 7, 2023

I’ll introduce how to resolve Error: Exit with error code: 126 when the Node.js version specified in .tool-versions doesn’t exist on Cloudflare Pages.

Background: Error When Using Latest Node.js LTS on Cloudflare Pages

When I tried to use the latest Node.js LTS version on Cloudflare Pages, the following error log was output and deployment failed.

2023-10-07T13:07:04.419035Z  Detected the following tools from environment: [email protected], [email protected]
2023-10-07T13:07:04.419523Z  Installing project dependencies: yarn
2023-10-07T13:07:04.827668Z  No preset version installed for command yarn
2023-10-07T13:07:04.828016Z  Please install a version by running one of the following:
2023-10-07T13:07:04.828213Z  
2023-10-07T13:07:04.828389Z  asdf install nodejs 18.18.0
2023-10-07T13:07:04.828545Z  
2023-10-07T13:07:04.828697Z  or add one of the following versions in your config file at /opt/buildhome/repo/.tool-versions
2023-10-07T13:07:04.839247Z  nodejs 14.21.3
2023-10-07T13:07:04.839524Z  nodejs 16.20.2
2023-10-07T13:07:04.839682Z  nodejs 18.17.1
2023-10-07T13:07:04.839851Z  nodejs 20.5.1
2023-10-07T13:07:04.844692Z  Error: Exit with error code: 126
2023-10-07T13:07:04.845006Z      at ChildProcess. (/snapshot/dist/run-build.js)
2023-10-07T13:07:04.845215Z      at Object.onceWrapper (node:events:652:26)
2023-10-07T13:07:04.845436Z      at ChildProcess.emit (node:events:537:28)
2023-10-07T13:07:04.845607Z      at ChildProcess._handle.onexit (node:internal/child_process:291:12)
2023-10-07T13:07:04.854278Z  Failed: build command exited with code: 1
2023-10-07T13:07:05.812512Z  Failed: error occurred while running build command

Solution: Install a Node.js Version Supported by Cloudflare Pages

The problem was resolved by installing a Node.js version supported by Cloudflare Pages.

diff --git a/.tool-versions b/.tool-versions
--- a/.tool-versions
+++ b/.tool-versions
@@ -1 +1 @@
-nodejs 18.18.0
+nodejs 18.17.1

That’s all from the Gemba, where I panicked when Error: Exit with error code: 126 occurred because the Node.js version specified in .tool-versions wasn’t available on Cloudflare Pages.