Skip to content

Commit

Permalink
add a custom error message for #2783
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Dec 31, 2022
1 parent 6837c35 commit 59fd941
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions lib/npm/node-install.ts
Expand Up @@ -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)}`);
}
Expand Down

0 comments on commit 59fd941

Please sign in to comment.