{"record":{"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":"error","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/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/npm/node-install.ts#L40-L76","documentation":"At the end of postinstall, validateBinaryVersion() (lib/npm/node-install.ts:57) compares the output of `<binary> --version` against packageJSON.version and throws if they differ. This guards against a native binary whose version does not match the JavaScript package, since the two speak a versioned wire protocol and a mismatch would cause confusing runtime failures.","triggerScenarios":"The esbuild binary that ends up on disk reports a different --version string than the esbuild JS package's version, e.g. due to a stale cached binary, a manual ESBUILD_BINARY_PATH override, or a partially-upgraded monorepo where the JS and native halves drifted.","commonSituations":"Upgrading esbuild but a leftover binary from the previous version remains; ESBUILD_BINARY_PATH env var pointing at an old build; monorepo with multiple esbuild versions cross-resolving; package manager hardlinking a mismatched @esbuild/* platform package.","solutions":["Remove node_modules and reinstall cleanly so the JS and native packages are the same version.","Unset the ESBUILD_BINARY_PATH environment variable (or update it to a matching binary).","Align esbuild versions across the whole monorepo (dedupe).","Clear the package manager cache and reinstall."],"exampleFix":"# before\nexport ESBUILD_BINARY_PATH=/old/path/esbuild   # stale binary\n\n# after\nunset ESBUILD_BINARY_PATH\nrm -rf node_modules && npm install","handlingStrategy":"validation","validationCode":"// Verify the on-disk binary version matches the JS package before first use.\nconst { execFileSync } = require('child_process')\nconst { version } = require('esbuild/package.json')\nfunction assertBinaryVersion(binPath) {\n  const out = execFileSync(binPath, ['--version']).toString().trim()\n  if (out !== version) {\n    throw new Error(`esbuild binary ${out} != js ${version}; reinstall esbuild`)\n  }\n}\nif (process.env.ESBUILD_BINARY_PATH) assertBinaryVersion(process.env.ESBUILD_BINARY_PATH)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid setting ESBUILD_BINARY_PATH to a stale binary across upgrades.","After upgrading esbuild, do a clean reinstall to refresh both JS and native halves.","Pin a single esbuild version across the whole monorepo to prevent drift."],"tags":["install","version-mismatch","native-binary","env"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}