{"id":"712951dd1d844f9b","repo":"evanw/esbuild","slug":"expected-json-stringify-packagejson-version-bu","errorCode":null,"errorMessage":"Expected ${JSON.stringify(packageJSON.version)} but got ${JSON.stringify(stdout)}","messagePattern":"Expected (.+?) but got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/npm/node-install.ts","lineNumber":58,"sourceCode":"      let os = 'this version of macOS'\n      try {\n        os = 'macOS ' + child_process.execFileSync('sw_vers', ['-productVersion']).toString().trim()\n      } catch {\n      }\n      throw new Error(`The \"esbuild\" package cannot be installed because ${os} is too outdated.\n\nThe Go compiler (which esbuild relies on) no longer supports ${os},\nwhich means the \"esbuild\" binary executable can't be run. You can either:\n\n  * Update your version of macOS to one that the Go compiler supports\n  * Use the \"esbuild-wasm\" package instead of the \"esbuild\" package\n  * Build esbuild yourself using an older version of the Go compiler\n`)\n    }\n    throw err\n  }\n  if (stdout !== packageJSON.version) {\n    throw new Error(`Expected ${JSON.stringify(packageJSON.version)} but got ${JSON.stringify(stdout)}`)\n  }\n}\n\nfunction isYarn(): boolean {\n  const { npm_config_user_agent } = process.env\n  if (npm_config_user_agent) {\n    return /\\byarn\\//.test(npm_config_user_agent)\n  }\n  return false\n}\n\nfunction fetch(url: string): Promise<Buffer> {\n  return new Promise((resolve, reject) => {\n    https.get(url, res => {\n      if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)\n        return fetch(res.headers.location).then(resolve, reject)\n      if (res.statusCode !== 200)\n        return reject(new Error(`Server responded with ${res.statusCode}`))","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/lib/npm/node-install.ts#L40-L76","documentation":"After install, `validateBinaryVersion` runs `esbuild --version` and requires the output to exactly equal `packageJSON.version` (the version declared in `npm/esbuild/package.json`). If the binary prints a different version, the package was assembled incorrectly: the JS shim and the native binary are out of sync.","triggerScenarios":"The postinstall hook runs the just-installed `esbuild` binary with `--version` and the printed version differs from the JS package's declared version. This indicates the wrong-platform binary got placed, a stale binary is on disk, or the package was republished with mismatched artifacts.","commonSituations":"A monorepo hoisting two different esbuild versions where the wrong binary is linked into the install dir; a third-party `esbuild` wrapper package shadowing the real binary; tampered/cached binary in a Docker layer; manual `ESBUILD_BINARY_PATH` pointing at an older esbuild; corrupted npm cache serving mismatched tarballs.","solutions":["Clear npm/yarn cache (`npm cache clean --force`) and reinstall so both JS and binary come from the same version.","Check for and remove duplicate esbuild versions across the dependency tree (`npm ls esbuild`).","Unset any `ESBUILD_BINARY_PATH` override pointing at a stale binary.","Rebuild Docker images from clean so no stale binary layer persists.","If using a vendored/forked esbuild, ensure its binary build embeds the same version string as the JS package.json."],"exampleFix":"# before: stale binary overrides\nexport ESBUILD_BINARY_PATH=/opt/old/esbuild-0.14.0\n\n# after\nunset ESBUILD_BINARY_PATH\nnpm cache clean --force && rm -rf node_modules && npm install","handlingStrategy":"validation","validationCode":"import { execFileSync } from 'child_process'\nimport pkg from 'esbuild/package.json'\nfunction verifyBinaryVersion(binPath: string) {\n  const v = execFileSync(binPath, ['--version']).toString().trim()\n  if (v !== pkg.version) {\n    throw new Error(`esbuild binary ${v} != package ${pkg.version}; reinstall esbuild`)\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid duplicate esbuild versions in the dependency tree (`npm ls esbuild`).","Never point ESBUILD_BINARY_PATH at a different-version binary.","Rebuild Docker images from clean to avoid stale binary layers.","Verify binary version after install in CI: `./node_modules/.bin/esbuild --version`."],"tags":["install","version-mismatch","native-binary","postinstall","caching"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}