@@ -2,6 +2,7 @@ import { existsSync } from 'fs'
22import { basename , extname , join , relative , isAbsolute , resolve } from 'path'
33import { pathToFileURL } from 'url'
44import findUp from 'next/dist/compiled/find-up'
5+ import semver from 'next/dist/compiled/semver'
56import * as Log from '../build/output/log'
67import * as ciEnvironment from '../server/ci-info'
78import {
@@ -1453,6 +1454,52 @@ function assignDefaultsAndValidate(
14531454 result . experimental . useCache = result . cacheComponents
14541455 }
14551456
1457+ // Node.js version gate for turbopackPluginRuntimeStrategy: 'workerThreads'.
1458+ // Older Node.js versions have memory safety bugs in worker threads. Bun and
1459+ // Deno are not affected by this check.
1460+ {
1461+ const strategy = result . experimental . turbopackPluginRuntimeStrategy
1462+ const isForced = strategy === 'forceWorkerThreads'
1463+ if ( strategy === 'workerThreads' || isForced ) {
1464+ // Normalize 'forceWorkerThreads' → 'workerThreads' for Rust/serde
1465+ result . experimental . turbopackPluginRuntimeStrategy = 'workerThreads'
1466+
1467+ const isBun = ! ! process . versions . bun
1468+ const isDeno = ! ! process . versions . deno
1469+ if ( ! isBun && ! isDeno ) {
1470+ const nodeVersion = process . versions . node
1471+ const WORKER_THREADS_SAFE_RANGE = '>=24.13.1 <25.0.0 || >=25.4.0'
1472+ if (
1473+ ! semver . satisfies ( nodeVersion , WORKER_THREADS_SAFE_RANGE , {
1474+ includePrerelease : true ,
1475+ } )
1476+ ) {
1477+ if ( isForced ) {
1478+ Log . warn (
1479+ `\`experimental.turbopackPluginRuntimeStrategy = ` +
1480+ `'forceWorkerThreads'\` has been enabled, but you're using ` +
1481+ `Node.js ${ nodeVersion } , which has known memory safety bugs ` +
1482+ `with worker threads used from the Node-API. You may ` +
1483+ `experience crashes, segmentation faults, or other ` +
1484+ `instability. Upgrade to Node.js ${ WORKER_THREADS_SAFE_RANGE } .`
1485+ )
1486+ } else {
1487+ Log . warn (
1488+ `\`experimental.turbopackPluginRuntimeStrategy = ` +
1489+ `'workerThreads'\` is set but has been ` +
1490+ `ignored because you're using Node.js ${ nodeVersion } , which ` +
1491+ `has memory safety bugs in worker threads. Falling back to ` +
1492+ `'childProcesses'. Upgrade to Node.js ` +
1493+ `${ WORKER_THREADS_SAFE_RANGE } .`
1494+ )
1495+ result . experimental . turbopackPluginRuntimeStrategy =
1496+ 'childProcesses'
1497+ }
1498+ }
1499+ }
1500+ }
1501+ }
1502+
14561503 // Store the distDirRoot in the config before it is modified for development mode
14571504 ; ( result as NextConfigComplete ) . distDirRoot = result . distDir
14581505 // Pre-compute the effective hash salt (used by both Webpack and Turbopack).
0 commit comments