-
Notifications
You must be signed in to change notification settings - Fork 31k
Turbopack: Add a check for node version before allowing workerThreads #91614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { existsSync } from 'fs' | |
| import { basename, extname, join, relative, isAbsolute, resolve } from 'path' | ||
| import { pathToFileURL } from 'url' | ||
| import findUp from 'next/dist/compiled/find-up' | ||
| import semver from 'next/dist/compiled/semver' | ||
| import * as Log from '../build/output/log' | ||
| import * as ciEnvironment from '../server/ci-info' | ||
| import { | ||
|
|
@@ -1453,6 +1454,52 @@ function assignDefaultsAndValidate( | |
| result.experimental.useCache = result.cacheComponents | ||
| } | ||
|
|
||
| // Node.js version gate for turbopackPluginRuntimeStrategy: 'workerThreads'. | ||
| // Older Node.js versions have memory safety bugs in worker threads. Bun and | ||
| // Deno are not affected by this check. | ||
| { | ||
| const strategy = result.experimental.turbopackPluginRuntimeStrategy | ||
| const isForced = strategy === 'forceWorkerThreads' | ||
| if (strategy === 'workerThreads' || isForced) { | ||
| // Normalize 'forceWorkerThreads' → 'workerThreads' for Rust/serde | ||
| result.experimental.turbopackPluginRuntimeStrategy = 'workerThreads' | ||
|
|
||
| const isBun = !!process.versions.bun | ||
| const isDeno = !!process.versions.deno | ||
| if (!isBun && !isDeno) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use a positive test instead? isNode?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't check for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😢 |
||
| const nodeVersion = process.versions.node | ||
| const WORKER_THREADS_SAFE_RANGE = '>=24.13.1 <25.0.0 || >=25.4.0' | ||
| if ( | ||
| !semver.satisfies(nodeVersion, WORKER_THREADS_SAFE_RANGE, { | ||
| includePrerelease: true, | ||
| }) | ||
| ) { | ||
| if (isForced) { | ||
| Log.warn( | ||
| `\`experimental.turbopackPluginRuntimeStrategy = ` + | ||
| `'forceWorkerThreads'\` has been enabled, but you're using ` + | ||
| `Node.js ${nodeVersion}, which has known memory safety bugs ` + | ||
| `with worker threads used from the Node-API. You may ` + | ||
| `experience crashes, segmentation faults, or other ` + | ||
| `instability. Upgrade to Node.js ${WORKER_THREADS_SAFE_RANGE}.` | ||
| ) | ||
| } else { | ||
| Log.warn( | ||
| `\`experimental.turbopackPluginRuntimeStrategy = ` + | ||
| `'workerThreads'\` is set but has been ` + | ||
| `ignored because you're using Node.js ${nodeVersion}, which ` + | ||
| `has memory safety bugs in worker threads. Falling back to ` + | ||
| `'childProcesses'. Upgrade to Node.js ` + | ||
| `${WORKER_THREADS_SAFE_RANGE}.` | ||
| ) | ||
| result.experimental.turbopackPluginRuntimeStrategy = | ||
| 'childProcesses' | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Store the distDirRoot in the config before it is modified for development mode | ||
| ;(result as NextConfigComplete).distDirRoot = result.distDir | ||
| // Pre-compute the effective hash salt (used by both Webpack and Turbopack). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already always pull in this dependency in the CLI to check your node.js version and exit the CLI with an error if you're on an unsupported version.