{"id":"aac3abc5f5412400","repo":"evanw/esbuild","slug":"you-installed-esbuild-for-another-platform-than-t","errorCode":null,"errorMessage":"\nYou installed esbuild for another platform than the one you're currently using.\nThis won't work because esbuild is written with native code and needs to\ninstall a platform-specific binary executable.\n${suggestions}\nAnother alternative is to use the \"esbuild-wasm\" package instead, which works\nthe same way on all platforms. But it comes with a heavy performance cost and\ncan sometimes be 10x slower than the \"esbuild\" package, so you may also not\nwant to do that.\n","messagePattern":"\nYou installed esbuild for another platform than the one you're currently using\\.\nThis won't work because esbuild is written with native code and needs to\ninstall a platform-specific binary executable\\.\n(.+?)\nAnother alternative is to use the \"esbuild-wasm\" package instead, which works\nthe same way on all platforms\\. But it comes with a heavy performance cost and\ncan sometimes be 10x slower than the \"esbuild\" package, so you may also not\nwant to do that\\.\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/npm/node-platform.ts","lineNumber":198,"sourceCode":"situation by installing esbuild with npm running inside of Rosetta 2 and then\ntrying to use it with node running outside of Rosetta 2, or vice versa (Rosetta\n2 is Apple's on-the-fly x86_64-to-arm64 translation service).\n\nIf you are installing with npm, you can try ensuring that both npm and node are\nnot running under Rosetta 2 and then reinstalling esbuild. This likely involves\nchanging how you installed npm and/or node. For example, installing node with\nthe universal installer here should work: https://nodejs.org/en/download/. Or\nyou could consider using yarn instead of npm which has built-in support for\ninstalling a package on multiple platforms simultaneously.\n\nIf you are installing with yarn, you can try listing both \"arm64\" and \"x64\"\nin your \".yarnrc.yml\" file using the \"supportedArchitectures\" feature:\nhttps://yarnpkg.com/configuration/yarnrc/#supportedArchitectures\nKeep in mind that this means multiple copies of esbuild will be present.\n`\n          }\n\n          throw new Error(`\nYou installed esbuild for another platform than the one you're currently using.\nThis won't work because esbuild is written with native code and needs to\ninstall a platform-specific binary executable.\n${suggestions}\nAnother alternative is to use the \"esbuild-wasm\" package instead, which works\nthe same way on all platforms. But it comes with a heavy performance cost and\ncan sometimes be 10x slower than the \"esbuild\" package, so you may also not\nwant to do that.\n`)\n        }\n\n        // If that didn't work too, then maybe someone installed esbuild with\n        // both the \"--no-optional\" and the \"--ignore-scripts\" flags. The fix\n        // for this is to just not do that. We don't attempt to handle this\n        // case at all.\n        //\n        // In that case we try to have a nice error message if we think we know\n        // what's happening. Otherwise we just rethrow the original error message.","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/lib/npm/node-platform.ts#L180-L216","documentation":"`generateBinPath` (`node-platform.ts:198`) throws this when the optional package for the *current* platform is missing, but a package for a *different* platform is found in `node_modules`. esbuild guesses the user copied a `node_modules` tree between platforms (Docker image build, WSL/Windows copy, Rosetta). The message includes platform-specific guidance (Rosetta for darwin x64↔arm64, supportedArchitectures for yarn).","triggerScenarios":"Platform-resolved `pkg` not resolvable, but `pkgForSomeOtherPlatform()` finds another `@esbuild/<platform>` directory in `node_modules`. Specifically: building on one OS/arch and copying `node_modules` to another; running under Rosetta 2 mismatch; building in Docker with the wrong base image.","commonSituations":"Multi-stage Docker builds that `COPY node_modules` from a build stage of a different OS/arch; WSL2 development with `node_modules` shared from Windows; macOS arm64 dev running x64-built dependencies under Rosetta; CI matrix where artifacts leak between jobs.","solutions":["Don't copy `node_modules` across platforms: run `npm ci` on the destination platform (e.g. inside the final Docker image).","Use a multi-arch Docker build (`docker buildx`) so each platform gets its own `node_modules`.","For yarn, list both architectures under `supportedArchitectures` in `.yarnrc.yml`.","On macOS arm64, ensure both npm and node run natively (not under Rosetta 2) before installing — use the universal node installer.","As a quick workaround, switch to `esbuild-wasm` which is platform-independent."],"exampleFix":"# before (Dockerfile)\nFROM node:18 AS build\nRUN npm install         # builds linux-x64 deps\nFROM --platform=linux/arm64 node:18\nCOPY --from=build /app/node_modules ./node_modules  # wrong arch!\n\n# after\nFROM --platform=linux/arm64 node:18\nCOPY package*.json ./\nRUN npm ci             # rebuilds node_modules for arm64","handlingStrategy":"validation","validationCode":"import os from 'os'\nconst want = `@esbuild/${platformToPkg(process.platform, os.arch(), os.endianness())}`\nimport { existsSync } from 'fs'\nimport { dirname } from 'path'\nfunction correctPlatformPackageInstalled(): boolean {\n  try { return existsSync(require.resolve(`${want}/bin/esbuild`).replace(/\\/bin.*/, '')) }\n  catch { return false }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never COPY node_modules between Docker stages of different platforms.","Run npm ci on the destination platform after copying source.","For yarn, declare all target platforms under supportedArchitectures.","On macOS arm64 ensure node runs natively (not under Rosetta).","Use multi-arch Docker builds (buildx) instead of copying node_modules."],"tags":["platform","docker","rosetta","wsl","node-modules-copy","install"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}