Skip to content

fix(standalone): correct symlink type in node_modules on Windows - #98606

Open
jat001 wants to merge 1 commit into
vercel:canaryfrom
jat001:canary
Open

fix(standalone): correct symlink type in node_modules on Windows#98606
jat001 wants to merge 1 commit into
vercel:canaryfrom
jat001:canary

Conversation

@jat001

@jat001 jat001 commented Sep 13, 2026

Copy link
Copy Markdown

What?

Fix incorrectly typed symlinks in .next/standalone/node_modules on Windows.

Why?

On Windows, fs.symlink() requires the type (file or dir) at creation time and defaults to file type when the target doesn't exist yet. In copyTracedFiles, symlinks are recreated in NFT trace order (arbitrary), so directory symlink targets may not exist when the symlink is created. This causes directory symlinks to be incorrectly created as file symlinks in the standalone output.

While this doesn't break runtime behavior (Windows resolves the target correctly), it produces incorrect output that can confuse tools and users inspecting the standalone directory.

How?

Detect the original file type via tracedFilePath (which points to the real file in the source tree) and pass the correct type explicitly to fs.symlink() on Windows.

Testing

Added unit test in test/production/standalone-mode/symlink-on-windows/ that directly exercises copyTracedFiles with both directory and file symlinks and verifies the output types are correct on Windows.

On Windows, symlinks have two distinct types (file or dir) that must be
specified at creation time. In `copyTracedFiles`, when recreating symlinks
in the standalone output directory, the symlink targets are relative paths
resolved relative to the output location. These targets may not yet exist
at creation time because files are copied in NFT trace order, not
dependency order.

When `fs.symlink()` is called on Windows with a non-existent target,
Node.js defaults to creating a file-type symlink. This causes directory
symlinks to be incorrectly created as file symlinks, breaking standalone
builds that rely on directory-level symlinks (e.g., workspace packages).

Fix by detecting the original file type via `tracedFilePath` (which
points to the real file in the source tree) and passing the correct type
explicitly to `fs.symlink()`.

Add unit test in `test/production/standalone-mode/symlink-on-windows/`
that directly exercises `copyTracedFiles` with both directory and file
symlinks and verifies the output types are correct on Windows.

Signed-off-by: Jat <chat@jat.email>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant