{"record":{"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":"error","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/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/npm/node-platform.ts#L180-L216","documentation":"In generateBinPath (lib/npm/node-platform.ts:128), when the current platform's package cannot be resolved, the downloaded fallback is absent, and require.resolve(pkg) fails, esbuild checks pkgForSomeOtherPlatform() which scans node_modules for any OTHER @esbuild/* platform package. If one is found, it concludes node_modules was built elsewhere and copied here, and throws this detailed message (lib/npm/node-platform.ts:198) explaining that a native, platform-specific binary cannot run cross-platform. A special Rosetta-2-specific sub-message is used for the darwin x64/arm64 mismatch case.","triggerScenarios":"node_modules containing an esbuild platform binary built for a different OS/arch than the one currently running: e.g. built on macOS/Windows then copied into a Linux Docker image, copied between Windows and WSL, or installed under Rosetta 2 then used natively.","commonSituations":"Docker builds that COPY a host-built node_modules into the image; WSL <-> Windows sharing of node_modules; installing npm under Rosetta 2 but running node natively (or vice versa); CI artifacts copied across runner OSes.","solutions":["Do not copy node_modules across platforms; run `npm ci` / `npm install` inside the target environment.","For Docker, copy package.json + lockfile and run the install during image build.","With yarn, list both platforms under supportedArchitectures in .yarnrc.yml.","For macOS Rosetta 2, install node with the universal installer and reinstall esbuild so both arches resolve.","Fall back to esbuild-wasm if a single cross-platform binary is mandatory."],"exampleFix":"# before (Dockerfile)\nCOPY . /app          # brings host's node_modules (wrong platform)\n\n# after\nCOPY package.json package-lock.json /app/\nRUN npm ci           # install correct platform binaries in-image\nCOPY . /app","handlingStrategy":"validation","validationCode":"// In a Dockerfile, never copy host node_modules; install in-image.\n// (Dockerfile snippet)\n// COPY package.json package-lock.json ./\n// RUN npm ci\n// COPY . .\n// Validate at CI start that node_modules was built on this platform:\nconst fs = require('fs')\nconst os = require('os')\nconst expect = `@esbuild/${process.platform}-${os.arch()}`\nif (!fs.existsSync(`node_modules/@esbuild/${process.platform}-${os.arch()}`)\n    && !fs.existsSync(`node_modules/@esbuild/${process.platform}-${os.arch() === 'x64' ? 'x64' : 'arm64'}`)) {\n  console.warn('node_modules may have been built on another platform; run npm ci here')\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never COPY node_modules between OS/arch boundaries; install inside the target image.","With yarn, declare supportedArchitectures for all target platforms.","On Apple Silicon, use the universal node installer and avoid mixing Rosetta 2 / native installs.","Pin builds to a single platform or use esbuild-wasm for cross-platform artifacts."],"tags":["platform","docker","wsl","rosetta","install","native-binary"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}