next.js
b690af09 - Reapply "[turbopack] Add bundling support for worker_threads" (#88725) (#88967)

Commit
17 hours ago
Reapply "[turbopack] Add bundling support for worker_threads" (#88725) (#88967) ## 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
Author
Parents
Loading