@@ -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 {
@@ -1443,6 +1444,52 @@ function assignDefaultsAndValidate(
14431444 result . experimental . useCache = result . cacheComponents
14441445 }
14451446
1447+ // Node.js version gate for turbopackPluginRuntimeStrategy: 'workerThreads'.
1448+ // Older Node.js versions have memory safety bugs in worker threads. Bun and
1449+ // Deno are not affected by this check.
1450+ {
1451+ const strategy = result . experimental . turbopackPluginRuntimeStrategy
1452+ const isForced = strategy === 'forceWorkerThreads'
1453+ if ( strategy === 'workerThreads' || isForced ) {
1454+ // Normalize 'forceWorkerThreads' → 'workerThreads' for Rust/serde
1455+ result . experimental . turbopackPluginRuntimeStrategy = 'workerThreads'
1456+
1457+ const isBun = ! ! process . versions . bun
1458+ const isDeno = ! ! process . versions . deno
1459+ if ( ! isBun && ! isDeno ) {
1460+ const nodeVersion = process . versions . node
1461+ const WORKER_THREADS_SAFE_RANGE = '>=24.13.1 <25.0.0 || >=25.4.0'
1462+ if (
1463+ ! semver . satisfies ( nodeVersion , WORKER_THREADS_SAFE_RANGE , {
1464+ includePrerelease : true ,
1465+ } )
1466+ ) {
1467+ if ( isForced ) {
1468+ Log . warn (
1469+ `\`experimental.turbopackPluginRuntimeStrategy = ` +
1470+ `'forceWorkerThreads'\` has been enabled, but you're using ` +
1471+ `Node.js ${ nodeVersion } , which has known memory safety bugs ` +
1472+ `with worker threads used from the Node-API. You may ` +
1473+ `experience crashes, segmentation faults, or other ` +
1474+ `instability. Upgrade to Node.js ${ WORKER_THREADS_SAFE_RANGE } .`
1475+ )
1476+ } else {
1477+ Log . warn (
1478+ `\`experimental.turbopackPluginRuntimeStrategy = ` +
1479+ `'workerThreads'\` is set but has been ` +
1480+ `ignored because you're using Node.js ${ nodeVersion } , which ` +
1481+ `has memory safety bugs in worker threads. Falling back to ` +
1482+ `'childProcesses'. Upgrade to Node.js ` +
1483+ `${ WORKER_THREADS_SAFE_RANGE } .`
1484+ )
1485+ result . experimental . turbopackPluginRuntimeStrategy =
1486+ 'childProcesses'
1487+ }
1488+ }
1489+ }
1490+ }
1491+ }
1492+
14461493 // Store the distDirRoot in the config before it is modified for development mode
14471494 ; ( result as NextConfigComplete ) . distDirRoot = result . distDir
14481495 if ( phase === PHASE_DEVELOPMENT_SERVER ) {
0 commit comments