Skip to content

fs.cpSync with dereference: true does not dereference (regression in 22.17) #59168

Description

@robhogan

Version

22.17.1 and 22.17.0

Platform

Darwin 24.5.0

Subsystem

fs

What steps will reproduce the bug?

workspace  nvm use 22.16
Using Node v22.16.0
 workspace  rm -rf node-repro; mkdir node-repro && cd node-repro && mkdir src linked && touch linked/foo && ln -s ../linked/foo src/bar && node -e "fs.cpSync('./src', './out', {dereference: true, recursive: true})" && ls -la out && cd ..
total 0
drwxr-xr-x  3 robhogan  staff   96 22 Jul 15:14 .
drwxr-xr-x  5 robhogan  staff  160 22 Jul 15:14 ..
-rw-r--r--  1 robhogan  staff    0 22 Jul 15:14 bar
 workspace  nvm use 22.17.0
Using Node v22.17.0
 workspace  rm -rf node-repro; mkdir node-repro && cd node-repro && mkdir src linked && touch linked/foo && ln -s ../linked/foo src/bar && node -e "fs.cpSync('./src', './out', {dereference: true, recursive: true})" && ls -la out && cd ..
total 0
drwxr-xr-x  3 robhogan  staff   96 22 Jul 15:14 .
drwxr-xr-x  5 robhogan  staff  160 22 Jul 15:14 ..
lrwxr-xr-x  1 robhogan  staff   47 22 Jul 15:14 bar -> /Users/robhogan/workspace/node-repro/linked/foo

How often does it reproduce? Is there a required condition?

Appears to reproduce consistently, no known conditions

What is the expected behavior? Why is that the expected behavior?

In all versions up to 22.17, when {dereference: true} was passed as an option to fs.cpSync, any symlinks in the source directory would be dereferenced and their targets copied to the destination.

What do you see instead?

In 22.17, a symlink is created in destination instead of a copy of the symlink's target, which is the same as {dereference: false}.

Additional information

Appears closely related to #58939 and probably has the same blame commit.

Activity

  1. jasnell commented on Jul 22, 2025

    @jasnell
    Member

    Yeah, this is one of the bugs I encountered when going through it, I just forgot to include it in the set described in #58939. Thank you for catching and documenting it! :-)

    /cc @anonrig ... fyi... appears to be another regression from the migration of cpSync into native code.

  2. added
    confirmed-bugIssues and PRs for confirmed bugs.
    fsIssues and PRs related to file-system APIs and the fs module.
    regressionIssues related to regressions.
    on Jul 22, 2025
  3. changed the title [-]fs.cp with dereference: true does not dereference (regression in 22.17)[/-] [+]fs.cpSync with dereference: true does not dereference (regression in 22.17)[/+] on Jul 22, 2025
  4. sommeeeer commented on Jul 26, 2025

    @sommeeeer

    Can confirm we have run into the same problem in @opennextjs/aws. Let me know if theres anything we can do to help out!

  5. berenddeboer commented on Dec 3, 2025

    @berenddeboer

    Seeing this in 24.11.1 too.

  6. everett1992 commented on Jun 3, 2026

    @everett1992
    Contributor

    This issue is not fixed in node v26.3.0 or v24.16.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.regressionIssues related to regressions.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions