Setup:
$ cd ~/tmp
$ touch a
$ mkdir b
$ ln -s b c
Then in Node.js:
> fs.cpSync('a', 'c', { dereference: false })
Uncaught Error: Cannot overwrite directory c with non-directory a
at cpSyncFn (node:internal/fs/cp/cp-sync:56:13)
at Object.cpSync (node:fs:3128:3) {
code: 'ERR_FS_CP_NON_DIR_TO_DIR'
}
> fs.cp('a', 'c', { dereference: false }, console.log)
undefined
> null undefined
The fs.cpSync call should not be throwing in this case and does not do so in Node.js v20.x. It throws in v22.x, v24.x, and main.
/cc @anonrig @nodejs/fs