From 59fd94138d7cc8fa7d88d409a68ec51f0f598538 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Fri, 30 Dec 2022 19:52:57 -0500 Subject: [PATCH] add a custom error message for #2783 --- lib/npm/node-install.ts | 49 +++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/npm/node-install.ts b/lib/npm/node-install.ts index f8c989817a0..c8840969cb5 100644 --- a/lib/npm/node-install.ts +++ b/lib/npm/node-install.ts @@ -13,20 +13,41 @@ let isToPathJS = true; function validateBinaryVersion(...command: string[]): void { command.push('--version'); - const stdout = child_process.execFileSync(command.shift()!, command, { - // Without this, this install script strangely crashes with the error - // "EACCES: permission denied, write" but only on Ubuntu Linux when node is - // installed from the Snap Store. This is not a problem when you download - // the official version of node. The problem appears to be that stderr - // (i.e. file descriptor 2) isn't writable? - // - // More info: - // - https://snapcraft.io/ (what the Snap Store is) - // - https://nodejs.org/dist/ (download the official version of node) - // - https://github.com/evanw/esbuild/issues/1711#issuecomment-1027554035 - // - stdio: 'pipe', - }).toString().trim(); + let stdout: string; + try { + stdout = child_process.execFileSync(command.shift()!, command, { + // Without this, this install script strangely crashes with the error + // "EACCES: permission denied, write" but only on Ubuntu Linux when node is + // installed from the Snap Store. This is not a problem when you download + // the official version of node. The problem appears to be that stderr + // (i.e. file descriptor 2) isn't writable? + // + // More info: + // - https://snapcraft.io/ (what the Snap Store is) + // - https://nodejs.org/dist/ (download the official version of node) + // - https://github.com/evanw/esbuild/issues/1711#issuecomment-1027554035 + // + stdio: 'pipe', + }).toString().trim(); + } catch (err) { + if (os.platform() === 'darwin' && /_SecTrustEvaluateWithError/.test(err + '')) { + let os = 'this version of macOS'; + try { + os = 'macOS ' + child_process.execFileSync('sw_vers', ['-productVersion']).toString().trim(); + } catch { + } + throw new Error(`The "esbuild" package cannot be installed because ${os} is too outdated. + +The Go compiler (which esbuild relies on) no longer supports ${os}, +which means the "esbuild" binary executable can't be run. You can either: + + * Update your version of macOS to one that the Go compiler supports + * Use the "esbuild-wasm" package instead of the "esbuild" package + * Build esbuild yourself using an older version of the Go compiler +`); + } + throw err; + } if (stdout !== ESBUILD_VERSION) { throw new Error(`Expected ${JSON.stringify(ESBUILD_VERSION)} but got ${JSON.stringify(stdout)}`); }