Skip to content

Commit

Permalink
fix #1462: avoid worker_threads in node <v12.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Jul 26, 2021
1 parent 1d3c103 commit 6d35ea9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

TypeScript recently [added support for `ES2021`](https://github.com/microsoft/TypeScript/pull/41239) in `tsconfig.json` so esbuild now supports this too. This has the same effect as if you passed `--target=es2021` to esbuild. Keep in mind that the value of `target` in `tsconfig.json` is only respected if you did not pass a `--target=` value to esbuild.

* Avoid using the `worker_threads` optimization in certain old node versions ([#1462](https://github.com/evanw/esbuild/issues/1462))

The `worker_threads` optimization makes esbuild's synchronous API calls go much faster than they would otherwise. However, it turns out this optimization cannot be used in certain node versions older than `v12.17.0`, where node throws an error when trying to create the worker. This optimization is now disabled in these scenarios.

Note that these old node versions are [currently in maintenance](https://nodejs.org/en/about/releases/). I recommend upgrading to a modern version of node if run-time performance is important to you.

## 0.12.15

* Fix a bug with `var()` in CSS color lowering ([#1421](https://github.com/evanw/esbuild/issues/1421))
Expand Down
15 changes: 15 additions & 0 deletions lib/npm/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ if (process.env.ESBUILD_WORKER_THREADS !== '0') {
worker_threads = require('worker_threads');
} catch {
}

// Creating a worker in certain node versions doesn't work. The specific
// error is "TypeError: MessagePort was found in message but not listed
// in transferList". See: https://github.com/nodejs/node/issues/32250.
// We just pretend worker threads are unavailable in these cases.
let [major, minor] = process.versions.node.split('.');
if (
// <v12.17.0 does not work
+major < 12 || (+major === 12 && +minor < 17)

// >=v13.0.0 && <v13.13.0 also does not work
|| (+major === 13 && +minor < 13)
) {
worker_threads = void 0;
}
}

// This should only be true if this is our internal worker thread. We want this
Expand Down

0 comments on commit 6d35ea9

Please sign in to comment.