diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16/package.json b/dev-packages/e2e-tests/test-applications/nextjs-16/package.json index 7006db5a96f2..b6a0ca8d853f 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-16/package.json +++ b/dev-packages/e2e-tests/test-applications/nextjs-16/package.json @@ -135,6 +135,12 @@ } ], "optionalVariants": [ + { + "runtime": "bun", + "build-command": "pnpm install", + "assert-command": "pnpm test:dev", + "label": "nextjs-16 (bun, turbopack, development)" + }, { "runtime": "cloudflare", "build-command": "pnpm test:build-latest:cloudflare", diff --git a/dev-packages/e2e-tests/test-applications/nextjs-16/playwright.config.mjs b/dev-packages/e2e-tests/test-applications/nextjs-16/playwright.config.mjs index dd8046fb9611..778035690610 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-16/playwright.config.mjs +++ b/dev-packages/e2e-tests/test-applications/nextjs-16/playwright.config.mjs @@ -28,6 +28,11 @@ const getStartCommand = () => { } if (testEnv === 'development') { + if (getRuntime() === 'bun') { + // Use the bin name, not its path: then Bun puts its `node` shim in PATH, which the Turbopack loader processes use. + return 'bun --bun next dev -p 3030 2>&1 | tee .tmp_dev_server_logs'; + } + return 'pnpm next dev -p 3030 2>&1 | tee .tmp_dev_server_logs'; } diff --git a/packages/nextjs/src/config/withSentryConfig/getFinalConfigObjectUtils.ts b/packages/nextjs/src/config/withSentryConfig/getFinalConfigObjectUtils.ts index 0d01bfa9bbc2..1ffbdf1773de 100644 --- a/packages/nextjs/src/config/withSentryConfig/getFinalConfigObjectUtils.ts +++ b/packages/nextjs/src/config/withSentryConfig/getFinalConfigObjectUtils.ts @@ -29,6 +29,10 @@ const MISSING_INSTRUMENTATION_FILE_WARNING_SHOWN = '__SENTRY_MISSING_INSTRUMENTA * With the default `'childProcesses'`, Next.js runs Turbopack loaders in `node` processes and puts `process.execArgv` * into their `NODE_OPTIONS`. On Bun, `execArgv` contains `--bun`, which Node.js does not accept, so the build fails or * hangs. `withSentryConfig` always adds loaders. + * + * `next dev` keeps the Next.js default. With worker threads, the loaders run in the dev server process, and Bun caches + * that `.next/dev` has no `node_modules` folder. The server then cannot load the externals that Turbopack links into + * `.next/dev/node_modules` later. */ export function maybeSetTurbopackPluginRuntimeStrategyOption( incomingUserNextConfigObject: NextConfigObject, @@ -36,7 +40,7 @@ export function maybeSetTurbopackPluginRuntimeStrategyOption( isTurbopack: boolean, silent?: boolean, ): void { - if (!process.versions.bun || !isTurbopack || !nextJsVersion) { + if (!process.versions.bun || !isTurbopack || !nextJsVersion || process.env.NODE_ENV === 'development') { return; } diff --git a/packages/nextjs/test/config/maybeSetTurbopackPluginRuntimeStrategyOption.test.ts b/packages/nextjs/test/config/maybeSetTurbopackPluginRuntimeStrategyOption.test.ts index 3b32d2456c28..baabe647edeb 100644 --- a/packages/nextjs/test/config/maybeSetTurbopackPluginRuntimeStrategyOption.test.ts +++ b/packages/nextjs/test/config/maybeSetTurbopackPluginRuntimeStrategyOption.test.ts @@ -8,6 +8,7 @@ describe('maybeSetTurbopackPluginRuntimeStrategyOption', () => { afterEach(() => { Object.defineProperty(process, 'versions', originalVersions); vi.restoreAllMocks(); + vi.unstubAllEnvs(); }); it.each(['16.2.0', '16.3.8', '17.0.0'])( @@ -46,6 +47,23 @@ describe('maybeSetTurbopackPluginRuntimeStrategyOption', () => { expect(warnSpy).not.toHaveBeenCalled(); }); + it('keeps the Next.js default in `next dev` on Bun', () => { + Object.defineProperty(process, 'versions', { ...originalVersions, value: { ...process.versions, bun: '1.4.5' } }); + vi.stubEnv('NODE_ENV', 'development'); + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const defaultConfig: NextConfigObject = {}; + const childProcessesConfig: NextConfigObject = { + experimental: { turbopackPluginRuntimeStrategy: 'childProcesses' }, + }; + + maybeSetTurbopackPluginRuntimeStrategyOption(defaultConfig, '16.4.6', true); + maybeSetTurbopackPluginRuntimeStrategyOption(childProcessesConfig, '16.4.6', true); + + expect(defaultConfig.experimental).toBeUndefined(); + expect(childProcessesConfig.experimental).toEqual({ turbopackPluginRuntimeStrategy: 'childProcesses' }); + expect(warnSpy).not.toHaveBeenCalled(); + }); + it('does not warn about `childProcesses` on Node.js', () => { const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); const config: NextConfigObject = { experimental: { turbopackPluginRuntimeStrategy: 'childProcesses' } };