next.js
b303bdcc - Turbopack: support turbopackIgnore on new URL() (#99965)

Commit
24 days ago
Turbopack: support turbopackIgnore on new URL() (#99965) ## Summary A user reported that `next build` fails on `new URL(options.workerUrl, import.meta.url)` inside a branch that only runs when the caller passes a worker URL. The analyzer sees the URL as `(<dynamic> | 'undefined')` and fails with `Module not found: Can't resolve (<dynamic> | 'undefined')`, and there was no way to mark the URL as runtime-only. - `new URL()` now honors the same magic comments as `new Worker()`. `new URL(/* turbopackIgnore: true */ url, import.meta.url)` (or `webpackIgnore`) creates no asset reference and is left as-is in the output, so the URL resolves at runtime. `turbopackOptional` suppresses the resolve error. The Turbopack docs list `new URL()` with the other supported expressions. - When a partially dynamic `new URL()`, `import()` or `require()` fails to resolve, the "Module not found" message suggests the matching `turbopackIgnore` comment. This adds a line to the existing `require()` warning in `execution/turbopack/resolving/dynamic`. Resolution behavior is otherwise unchanged: a partially dynamic `new URL()` that fails to resolve is still an error. For a third-party package that can't be annotated, `turbopack.ignoreIssue` in `next.config` remains the way to suppress it. ## Verification - `cargo nextest run -p turbopack-core -p turbopack-ecmascript -p turbopack-tests`: `snapshot/imports/ignore-comments`, which covers `turbopackIgnore` on `new Worker()`, is unchanged. 15 turbopack-core `resolve::` tests fail locally on macOS with a `/var` vs `/private/var` temp-dir error; the same 15 fail on `canary`. <!-- NEXT_JS_LLM --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Author
Parents
Loading