mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
## What? This PR reapplies #87746 which adds bundling support for Node.js `worker_threads` in Turbopack. ## Why? The original PR (#87746) was reverted in #88725 because it broke builds that use packages like `pino` with transports. These packages use dynamic patterns like `join(__dirname, 'lib', 'worker.js')` to resolve worker entry points, which can match non-evaluatable files like `package.json` or `tsconfig.json`. ## How? This PR reapplies the original changes with the following fixes: 1. **Downgrade errors to warnings in tracing contexts**: When `loose_errors` is enabled (tracing mode) or `in_try` is true, worker entry point validation errors are now emitted as warnings instead of errors. This follows the established Turbopack pattern used in `handle_resolve_error` and other resolve error handling. 2. **Improved error messages**: Error messages for non-chunkable and non-evaluatable worker entry point modules now include: - The module identifier (so you can see which file caused the issue) - The issue source location (pointing to the `new Worker()` call in source code) 3. **Added regression test**: A new pino-based test case exercises the `thread-stream` worker pattern that caused the original failure. This test runs in `CodeGenerationAndTracing` mode via `test-start-turbo`. ## Changes from original PR - Added `source` field to `CodeGenerationIssue` to support showing issue source locations - Added `get_issue_severity()` helper that checks `loose_errors` and `in_try` to determine severity - Fixed typo: `"SharedbWorker"` → `"SharedWorker"` in `to_string` implementation - Added pino regression test in `test/e2e/app-dir/node-worker-threads/` ## Testing - ✅ `pnpm test-dev-turbo test/e2e/app-dir/node-worker-threads/` - all tests pass - ✅ `pnpm test-start-turbo test/e2e/app-dir/node-worker-threads/` - all tests pass (exercises bundling mode) - ✅ Verified test fails without the `loose_errors` fix - ✅ Verified vercel-docs build succeeds with warnings instead of errors
33 lines
906 B
TypeScript
33 lines
906 B
TypeScript
import { NextResponse } from 'next/server'
|
|
import pino from 'pino'
|
|
|
|
export async function GET() {
|
|
try {
|
|
// Create a pino logger with a transport
|
|
// This internally uses thread-stream which creates worker_threads
|
|
const logger = pino({
|
|
transport: {
|
|
target: 'pino/file',
|
|
options: { destination: 1 }, // stdout
|
|
},
|
|
})
|
|
|
|
// Log a test message - this triggers the transport worker
|
|
logger.info('pino test message')
|
|
|
|
// Flush the logger to ensure the message is sent
|
|
// Use nextTick to allow async initialization of the transport
|
|
await new Promise((resolve) => process.nextTick(resolve))
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: 'pino logger with transport initialized successfully',
|
|
})
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ success: false, error: String(error) },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|