## Why?
The current error message when you have have a set `weight: ['400', '700']` and set `axes: ['wdth']` for a variable font is confusing—it should mention to correct your weight property (e.g., `weight: 'variable'` or nothing at all for `weight`).
- Fixes https://github.com/vercel/next.js/issues/72413
A small PR to start inserting nft on the critical path. This is only enabled in production builds and implements the bare minimum to get NFT outputs by inserting it into the server assets.
Followed up by another PR and inserts more hooks / flags elsewhere in the APIs.
### What?
This is a 2nd prefactor for adding node-file-trace into turbopack. When implementing this, we have a few options namely:
- a) expose turbotrace (node-file-trace-rs) as a napi library and try to insert it into the current codebase
- b) expose turbotrace and try to reuse the turbo backend
- c) move turobtrace into the rust process and do it in parallel with everything else
We chose c
We have already ripped out the js code path, this PR nukes the now-orphaned node-file-trace rust binary and napi bindings.
### Why?
The crate is unmaintained and probably will not be used in its current form.
### What?
Add an option to disable SWC minfiier for turbopack builds.
### Why?
Disabling minification was useful for debugging and @sokra suggested adding it as an option under `experimental.turbo`.
### How?
Closes PACK-3371
I noticed we were using a pretty old version of indexmap, this updates that.
`indexmap 1.9.3` still exists in the lockfile as there are some other dependencies we have (mostly `wasmer`) that pull it, but as those dependencies are updated, we'll get rid of it.
I specified the lower version range bound as `2.5.0` instead of `2.6.0` because I wanted to avoid introducing [yet another minor version of hashbrown](https://github.com/indexmap-rs/indexmap/blob/master/RELEASES.md), which might *slightly* help with compilation times. This is just a lower bound, so eventually we'll end up on `2.6.0` (or a later version) if dependency asks for it.
Closes PACK-3406
the `next_font_loaders` transform replaces imports from `next/font` with
slightly different ones. unfortunately it was inserting these imports
**at the top** of the file, which broke the `server_actions` transform
because it expects "use server"/"use cache" directives to be the first
item in the file.
this PR changes the logic in the font transform to insert the import in
the place where the original `next/font` import occurred instead of at
the top of the file.
(i suppose that we could just reorder the transforms and run
`server_actions` before `next_font_loaders`, but this feels more robust)
Fixes#72179
Part of NFT
~~Dynamic requests such as `require("./"+ something)` often match too
many files. If we cannot process a matched file with the Turbopack
rules, then it's really an unreachable case anyway. This removes the
error in that case.~~
This doesn't change the behavior of regular bundling, but makes
`primary_modules_raw_iter` not throw the error.
- [x] Cleanup API: add the boolean into `.process()`? Or should this be
passed differently?
- [ ] ~~Should this be a warning instead for user code?~~
Follow-up to #68056, adding support for export default declarations with function expressions, e.g.:
```tsx
export default function Page() {
useEffect(() => {})
}
```
Enabling this feature will be done in a future PR.
With this PR, `turbo-tasks-memory` (the new backend doesn't support this yet) can print invalidation information (basically just function names) to stdout when run with the following environment variable:
```
NEXT_TURBOPACK_PRINT_TASK_INVALIDATION=1
```

This was previously behind a compilation feature flag, however:
- We have to generate all the support code regardless of if the flag is set, so it doesn't seem like it would save us anything on binary size.
- The branch should be pretty cheap to check (and probably easy for the CPU to predict), so runtime performance when this flag isn't set should be negligible.
- It's a pretty big lift to ask users to try custom builds.
**Why?** The hope is that this can help debug cases where users get stuck in a fast refresh update loop: https://vercel.slack.com/archives/C03S8ED1DKM/p1730737898652749
This is similar to #72300, except that prints the *reason*, this prints the *tasks* that were actually invalidated. Printing the tasks works even if no reason was supplied, so it can probably be helpful in debugging those cases.
Closes PACK-3375
A hand refactor of all the remaining struct fields from `Vc` to `ResolvedVc`, to unblock local tasks.
This is similar to #71948, as there's a focus on resolve options.
Note: "resolve" in this context means two different things. `turbopack-resolve` is about resolving module locations on disk. `ResolvedVc` is about resolving "cells" representing incremental computations.
Closes PACK-3369
A hand refactor of the `OutputAssets` type in `turbopack-core` to use `ResolvedVc`. This is one of the more common types passed around turbopack, so this touches a lot of code.
Closes PACK-3358
A hand refactor of all the remaining struct fields in `turbopack-resolve` to `ResolvedVc`.
Note: "resolve" in this context means two different things. `turbopack-resolve` is about resolving module locations on disk. `ResolvedVc` is about resolving "cells" representing incremental computations.
Closes PACK-3344
A hand refactor of the `Modules` (and `OptionModule`) type in `turbopack-core` to use `ResolvedVc`. This is one of the more common types passed around turbopack, so this touches a lot of code.
Closes PACK-3343
Context
- I only fixed webpack codepath for
https://github.com/vercel/next.js/pull/72056
- But we ended up merging it despite the fact the CI would fail due to
Github incident https://www.githubstatus.com/incidents/9yk1fbk0qjjc
Notes
- `middleware.rs` only runs in build time for production turbopack build
- without this fix, the test would fail on 404 for prod mode, but would
land on Chat page for dev mode
After adding validation that fixing invalid segment configs (when DIO is
enabled), it revealed that errors weren't being displayed in Turbopack,
because `setHMRServerError` wasn't implemented.
This refactors the implementation to use the existing server component
transform when validating if the segments are valid. This has the
benefit of highlighting precisely where the segment is coming, making it
easier to remove. The test that was skipped in Turbopack is also
re-enabled.
<details>
<summary>Screenshot</summary>

</details>
The Google fonts API requires this. Previously, `get_stylesheet_url`
trusted that the weight axis inputs were sorted correctly, which they
may not be.
This PR creates and uses two new enums:
- `FontAxesWeights`, to capture weights as ints, and moves the
responsibility of sorting weights into `get_stylesheet_url` itself.
- `VariantValue` to wrap each value for variants, as these can be either
a string (an expression representing a variable font weight range) or a
`u16`, representing a fixed font weight. This allows us to defer
stringifying these until format time while still comparing them for
ordering.
Test Plan: Added a unit test for `get_stylesheet_url`.
Closes PACK-3359
Closes PACK-3356
### What?
We previously supported a flag `experimental.turbotrace` which would opt in to using turbo-tasks powered machinery for performing the tasks that were previously handled by node-file-trace. There was a bifurcation where both turbopack and webpack would use either node-file-trace or the new turbotrace which lead to untested code paths. This never really gained traction on the webpack side and, with the decision to move turbotrace and nft generation directly into the critical path of a turbo build (as opposed to a post-processing step) is obsolete for turbopack. We rip it out.
### Why?
See above
### How?
Remove the flag, and the code path branches that refer to it. I opted to keep some formatting to preserve the diff but may refactor the now-rustless code later as there is still some control flow that is unnecessary.
With this PR, we're adding one extra leading byte to Server Reference
IDs (both Server Actions and `"use cache"` functions), to include some
static information about the function itself.
The information byte has the following format:
```
0 000000 0
^type ^arg mask ^rest args
```
The type bit represents if the action is a cache function or not. For
cache functions, the type bit is set to `1`. Otherwise, it's `0`.
The arg mask bit is used to determine which arguments are used by the
function itself, up to 6 arguments. The bit is set to `1` if the
argument is used, or being spread or destructured (so it can be
indirectly or partially used). The bit is set to `0` otherwise.
The rest args bit is used to determine if there's a `...` rest argument
in the function signature. If there is, the bit is set to `1`.
For example:
```tsx
async function foo(a, foo, b, bar, ...baz) {
'use cache';
return a + b;
}
```
will have it encoded as `[1][101011][1]`. The first bit is set to `1`
because it's a cache function. The second part has `1010` because the
only arguments used are `a` and `b`. The subsequent `11` bits are set to
`1` because there's a `...baz` argument starting from the 5th. The last
bit is set to `1` as well for the same reason.
Note: Currently in this PR we don't track if an argument is actually
referenced in the function body or not. That will be implemented as a
follow-up optimization.
Also, the reference ID is currently hex-encoded so there will be exact 2
characters for easier decoding. This encoding might change though.
With this extra byte, the client can do some further optimizations. More
details can be found in the code comment.
Generated using a version of https://github.com/vercel/turbopack-resolved-vc-codemod using Anthropic Claude Sonnet 3.5 (`claude-3-5-sonnet-20241022`) for more complicated errors we don't have hardcoded logic for.
- Part 1: #70927
- Part 2: #71172
I kept running the script until I ran out of tokens (the tier 1 rate limit is 1M input tokens). I'll keep improving how I'm calling the LLM (there's still a lot of room for improvement from my side), and try running it again tomorrow to fix more things.
This fixes 13 struct field types. There are still 271 struct fields remaining that need to be codemodded.
Changes `--turbo` -> `--turbopack` to avoid confusion.
- Updated docs
- Updates create-next-app -- For create-next-app it's a rename as
otherwise there is an ordering problem with the prompts
- For the CLI `next dev --turbo` is still supported, will eventually be
a warning in a future version to swap with `--turbopack` but is not a
requirement today, can be handled automatically by the upgrade codemod
- New CLI flag: `next dev --turbopack`
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:
## For Contributors
### Improving Documentation
- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide
### Adding or Updating Examples
- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md
### Fixing a bug
- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md
### Adding a feature
- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md
## For Maintainers
- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change
### What?
### Why?
### How?
Closes NEXT-
Fixes #
-->
---------
Co-authored-by: Will Binns-Smith <wbinnssmith@gmail.com>
**This is a** *(mostly)* **machine-generated PR.**
This uses a much updated version of the ast-grep based codemod script from #70927, which can now match a bunch more patterns.
Codemod scripts: https://github.com/vercel/turbopack-resolved-vc-codemod/tree/90518e64cfaf9328546ff4688692f16f54d4fc3e
I did a small bit of cleanup after running the script with:
```bash
sg -U --pattern '$OBJ.resolve().await?.to_resolved().await?' -r '$OBJ.to_resolved().await?'
```
Notable additions since last time are:
- Runs the compiler/fixer in a loop a few times, as fixing an issue often allows compilation to get further, creating new errors.
- Can apply compiler-suggested edits (usually these are manual derefs needed with `*`)
- Knows how to rewrite `$OBJ.cell()` to `$OBJ.resolved_cell()`
- Knows how to rewrite `Vc::cell($ARG)` to `ResolvedVc::cell($ARG)`
- Knows how to rewrite `$TYPE::cell($ARG)` to `$TYPE::resolved_cell($ARG)`.
- Knows how to add `.to_resolved().await?` to expressions.
### Why?
When handling the `opengraph-image` size exceeding the limit, we mapped
with string literal between Rust and JavaScript. The Rust string literal
contains backslashes `\` on Windows, incompatible with JavaScript string
syntax.
Fixes#71582
---------
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
Closes PACK-3304
This was originally done in https://github.com/vercel/next.js/pull/63209
But I don't think this is correct.
Without this change, the added test fails with
```
Error: failed to pipe response
at pipeToNodeResponse (/next.js/packages/next/dist/server/pipe-readable.js:126:15)
at async handleRequest (/next.js/packages/next/dist/server/lib/router-server.js:275:24)
at async requestHandlerImpl (/next.js/packages/next/dist/server/lib/router-server.js:384:13)
at async Server.requestListener (/next.js/packages/next/dist/server/lib/start-server.js:142:13) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:405:5)
at new URL (node:internal/url:676:13)
at /next.js/test/tmp/next-test-1729241452365-597/.next/server/edge/chunks/ssr/[project]_packages_next_dist_compiled_fd94e8._.js:31684:26 {
input: '/_next/static/media/noto-sans-v27-latin-regular.7e1666d1.ttf',
code: 'ERR_INVALID_URL'
}
}
```
(because the `blob:` prefix is missing for the font static URL)
With this PR, we're assigning names to the transformed `"use cache"`
functions, using the same rules as in #71478. Since we can't use named
function expressions here, we're using `Object.defineProperty` instead,
which we already used in #71478 for server actions with default export
expressions.
In addition, this PR fixes source mapping of `"use cache"` functions,
which was slightly off before, due to the wrong spans being assigned to
the new expressions.
**Before:**
<img width="943" alt="before"
src="https://github.com/user-attachments/assets/f7cf674c-32d4-4f0d-a304-d5de5637a6a1">
**After:**
<img width="943" alt="after"
src="https://github.com/user-attachments/assets/8edda482-a666-4431-bfad-7e21987331eb">
When importing a server action module from a client component, we've
already opted into the server layer, so defining inline `"use cache"`
annotated functions should be allowed.
Follow-up to #71497, adding support for exporting a function from a
`"use cache"` module using a default export expression, e.g.:
```ts
"use cache"
const foo = async () => {}
export default foo
```
Updated error messages to differentiate between the two different directives.
### `"use server"`
- `Server Actions must be async functions.`
- `Only async functions are allowed to be exported in a "use server" file.`
### `"use cache"`
- `"use cache" functions must be async functions.`
- `Only async functions are allowed to be exported in a "use cache" file.`
This PR adjusts the server action transforms to assign proper function names for the generated server reference proxies.
- If the original function has a name, this name is used.
- If a function expression is assigned to a variable, the variable's name is used.
- If an anonymous function expression is assigned to a prop, the prop's name is used.
In addition, this PR simplifies the output for exported functions, avoiding unnecessary `registerServerReference` calls.
It also fixes the source mapping of default exported server actions.
**Before:**
<img width="890" alt="before" src="https://github.com/user-attachments/assets/a3d6a5f8-d48e-474d-8f03-b49306fb704f">
**After:**
<img width="890" alt="after" src="https://github.com/user-attachments/assets/8f332690-6c26-46f1-9eef-7680f47ea578">
Next up, we will do the same for `'use cache'` functions.
- Make UnableToExternalize a warning
- Special case that warning so that it's still printed even inside
node_modules
- Make sure that it's only printed once
- Also refactors `AppEndpoint` a bit (pulling code out into functions
and hoist common function calls for Node/Edge)
- Use the `server/app/.../page.js` RSC entry chunks in the
`rscModuleMapping` to not have to generate extra chunks.
Alternative implementation for
https://github.com/vercel/next.js/pull/71304Closes#71304
- [x] ~~It fails with this strange error though:~~
```
Error: Cannot find module '../chunks/ssr/[turbopack]_runtime.js'
Require stack:
next.js/test/e2e/app-dir/use-cache/.next/server/chunks/ssr/[turbopack]_runtime.js
next.js/test/e2e/app-dir/use-cache/.next/server/app/page.js
```
---------
Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
### What?
refactor BackingStore to allow different KeyValueDatabases, avoid
dynamic calls and have ReadTransactions and ValueBuffer as trait
associated type.
Also adds a default backing storage to be used by next.js