Skip to content

Commit

Permalink
chore: log useful error for Node v14 breakage (#5732)
Browse files Browse the repository at this point in the history
* chore: Useful error for Node v14 breakage

There is currently a bug with extract-zip and Node v14.0.0 that
causes extractZip to silently fail:
#5719

Rather than silenty fail if the user is on Node 14 we instead
detect that and throw an error directing the user to that bug. The
rejection message below is surfaced to the user in the command line.

The issue seems to be in streams never resolving so we wrap the call in
a timeout and give it 100ms to resolve before deciding on an error. If
the user is on Node < 14 we maintain the behaviour we had before this
patch.

Here's how this change impacts the output on Node 14 and Node 10:

Node 10:

```
npm run tsc && rm -r .local-* && node install

> puppeteer@3.0.1-post tsc /Users/jacktfranklin/src/puppeteer
> tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/

Version 3.8.3
Downloading Chromium r737027 - 118.4 Mb [====================] 100% 0.0s
Chromium (737027) downloaded to /Users/jacktfranklin/src/puppeteer/.local-chromium/mac-737027
```

---

Node 14 without this patch:

```
npm run tsc && rm -r .local-* && node install

> puppeteer@3.0.1-post tsc /Users/jacktfranklin/src/puppeteer
> tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/

Version 3.8.3
Downloading Chromium r737027 - 118.4 Mb [====================] 100% 0.0s
```

Note that whilst it doesn't error, it doesn't complete the install. We
don't get the success message that we saw above in the Node 10 install.

---

Node 14 with this patch:

```npm run tsc && rm -r .local-* && node install

> puppeteer@3.0.1-post tsc /Users/jacktfranklin/src/puppeteer
> tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/

Version 3.8.3
Downloading Chromium r737027 - 118.4 Mb [====================] 100% 0.0s
ERROR: Failed to set up Chromium r737027! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.
Puppeteer currently does not work on Node v14 due to an upstream bug. Please see #5719 for details.
```

The explicit message should save users a good amount of debugging time.
  • Loading branch information
jackfranklin committed Apr 27, 2020
1 parent a7d2485 commit 1b9d9e9
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/BrowserFetcher.ts
Expand Up @@ -321,10 +321,45 @@ function install(archivePath: string, folderPath: string): Promise<unknown> {
}

async function extractZip(zipPath: string, folderPath: string): Promise<void> {
try {
await extract(zipPath, {dir: folderPath});
} catch (error) {
return error;
const nodeVersion = process.version;

/* There is currently a bug with extract-zip and Node v14.0.0 that
* causes extractZip to silently fail:
* https://github.com/puppeteer/puppeteer/issues/5719
*
* Rather than silenty fail if the user is on Node 14 we instead
* detect that and throw an error directing the user to that bug. The
* rejection message below is surfaced to the user in the command
* line.
*
* The issue seems to be in streams never resolving so we wrap the
* call in a timeout and give it 10s to resolve before deciding on
* an error.
*
* If the user is on Node < 14 we maintain the behaviour we had before
* this patch.
*/
if (nodeVersion.startsWith('v14.')) {
let timeoutReject;
const timeoutPromise = new Promise((resolve, reject) => { timeoutReject = reject; });

const timeoutToken = setTimeout(() => {
const error = new Error(`Puppeteer currently does not work on Node v14 due to an upstream bug. Please see: https://github.com/puppeteer/puppeteer/issues/5719 for details.`);
timeoutReject(error);
}, 10 * 1000);

await Promise.race([
extract(zipPath, {dir: folderPath}),
timeoutPromise
]);

clearTimeout(timeoutToken);
} else {
try {
await extract(zipPath, {dir: folderPath});
} catch (error) {
return error;
}
}
}

Expand Down

0 comments on commit 1b9d9e9

Please sign in to comment.