esbuild で「You installed esbuild for another platform」が出て起動できない
You installed esbuild for another platform は、別 OS で入れた node_modules を持ち込むと出る。
動かす側で node_modules を消して npm ci し直せば直る。
公開: 更新:
npx esbuild --version … throw new Error(` ^ Error:
npx esbuild --version 0.28.2
2026-10-27 に node:22-bookworm-slim(Node.js 22.23.4 / npm 10.9.9) で実際に打って取った出力。検証環境の詳細
要約
esbuild を CLI で実行しても、JavaScript API から呼んでも、次のエラーで止まる。
Error:
You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.
Specifically the "@esbuild/win32-x64" package is present but this platform
needs the "@esbuild/linux-x64" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.esbuild の本体は Go で書かれたネイティブバイナリで、npm からは OS と CPU ごとのパッケージ(@esbuild/linux-x64・@esbuild/win32-x64 など)として入る。
インストールした環境の分だけが node_modules に入るので、別の OS へ node_modules を持ち込むと、その OS 用のバイナリが無くて起動できない。
Windows 11 で npm install esbuild(0.28.2)した node_modules を、Linux の node:22-bookworm-slim コンテナにマウントして実行すると、上の表示になった。
実行例
@esbuild/win32-x64 だけが入った node_modules を node:22-bookworm-slim に置いて npx esbuild --version を実行すると、別の OS 用のバイナリだという Error で終了コード 1 になった。node_modules を消して npm ci し直すと @esbuild/linux-x64 に入れ替わり、0.28.2 を返して終了コード 0 で終わった。
$ ls node_modules/@esbuild
win32-x64$ npx esbuild --version
/tmp/tmp.0nQo6MpZJn/node_modules/esbuild/bin/esbuild:170
throw new Error(`
^
Error:
You installed esbuild for another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.
Specifically the "@esbuild/win32-x64" package is present but this platform
needs the "@esbuild/linux-x64" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.
If you are installing with npm, you can try not copying the "node_modules"
directory when you copy the files over, and running "npm ci" or "npm install"
on the destination platform after the copy. Or you could consider using yarn
instead of npm which has built-in support for installing a package on multiple
platforms simultaneously.
If you are installing with yarn, you can try listing both this platform and the
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.
Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.
at generateBinPath (/tmp/tmp.0nQo6MpZJn/node_modules/esbuild/bin/esbuild:170:17)
at Object.<anonymous> (/tmp/tmp.0nQo6MpZJn/node_modules/esbuild/bin/esbuild:218:27)
at Module._compile (node:internal/modules/cjs/loader:1781:14)
at Object..js (node:internal/modules/cjs/loader:1913:10)
at Module.load (node:internal/modules/cjs/loader:1505:32)
at Function._load (node:internal/modules/cjs/loader:1309:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:254:19)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:171:5)
at node:internal/main/run_main_module:36:49
Node.js v22.23.4
$ echo $?
1$ rm -rf node_modules$ npm ci
added 2 packages, and audited 3 packages in 626ms
found 0 vulnerabilities$ ls node_modules/@esbuild
linux-x64$ npx esbuild --version
0.28.2
$ echo $?
0— 2026-10-27 時点の出力
検証環境Node.js 22.23.4 / npm 10.9.9 / 2026-10-27 検証
- 検証日
- 実行環境
node:22-bookworm-slimDebian GNU/Linux 12 (bookworm)- バージョン
- Node.js 22.23.4
- npm 10.9.9
この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。
解決策
1. node_modules をイメージに入れず、中で npm ci する
.dockerignore に node_modules を書き、依存はイメージの中で入れ直す。
node_modulesFROM node:22-bookworm-slim
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .Windows で作った package-lock.json のままでも、Linux の npm ci は @esbuild/linux-x64 を入れた。
ロックファイルには各プラットフォーム用のパッケージが並んでいて、npm ci は実行している環境に合うものを選ぶ。.dockerignore を置かずに COPY . . だけにした Dockerfile は、RUN npx esbuild の段階で同じエラーになった。
2. bind mount では node_modules を分ける
Compose でソースを bind mount するときは、node_modules に名前付きボリュームを重ね、コンテナ側の依存をホストと分ける。
services:
app:
build: .
volumes:
- ./:/app
- node_modules:/app/node_modules
volumes:
node_modules:マウントの重なり方は docker compose のボリュームマウントで node_modules が消えるで詳しく扱っている。
3. 動かす側で入れ直す
WSL など、実行する環境で node_modules を消して入れ直す。
コンテナの中で次を実行すると @esbuild/linux-x64 に入れ替わり、esbuild が起動した。
rm -rf node_modules
npm ciesbuild のドキュメント(新しいタブで開く)も、npm と pnpm では node_modules をコピーせず、コピー先で npm ci か npm install を実行する方法を挙げている。
Yarn なら .yarnrc.yml の supportedArchitectures に両方の環境を書き、複数の OS 用のバイナリを同時に入れておく方法もある。
よくある原因
COPY . .でnode_modulesごとコピーしている。.dockerignoreが無いと、ホストのnode_modulesがビルドコンテキストに含まれ、イメージに入る。- bind mount でホストの
node_modulesが見えている。docker run -v "$PWD:/app"や Compose の./:/appでは、コンテナの/app/node_modulesはホスト側のディレクトリそのものになる。 - Windows と WSL で依存を使い回している。
Windows 側で入れたプロジェクトを WSL から開いて実行すると、Linux 用のバイナリが無い。