Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

Why fs.cpSync Leaves Symlinks Pointing at the Cache—and How to Copy Their Targets

By default, fs.cpSync preserves symlinks. Set dereference: true to request copying their targets, then verify the runtime, options, and link layout.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If fs.cpSync copied a framework but its symlinks still point into a cache, check the options used for the copy. Node.js documents dereference as false by default, so a default copy preserves links rather than copying the files they reference. To request copies of the targets, set dereference: true. The exact cause still depends on the Node.js version, the actual options, and the source and destination layout.

Why the copied framework still points to the cache

By default, fs.cpSync copies symlinks as symlinks. That means the destination can contain a link whose target is still a cache path rather than a copied file. The Node.js File system API documentation describes dereference as “dereference symlinks. Default: false.”

As an Amazon Associate I earn from qualifying purchases.

This explains the result if the call omitted dereference or set it to false; the title alone does not establish what options were passed or which Node.js version ran the copy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Copy the symlink targets instead

Set dereference: true in the options passed to fs.cpSync. If you are copying a directory tree, use recursive: true as well:

#1 Best Overall
Sandisk 2TB Extreme Portable SSD, Up to 1050MB/s, USB-C, USB 3.2 Gen 2, IP65 Water and Dust Resistance, Updated Firmware, External Solid State Drive, SDSSDE61-2T00-G25
  • Get NVMe solid state performance with up to 1050MB/s read and 1000MB/s write speeds in a portable, high-capacity drive(1) (Based on internal testing; performance may be lower depending on host device & other factors. 1MB=1,000,000 bytes.)
  • Up to 3-meter drop protection and IP65 water and dust resistance mean this tough drive can take a beating(3) (Previously rated for 2-meter drop protection and IP55 rating. Now qualified for the higher, stated specs.)
  • Use the handy carabiner loop to secure it to your belt loop or backpack for extra peace of mind.
  • Help keep private content private with the included password protection featuring 256‐bit AES hardware encryption.(3)
  • Easily manage files and automatically free up space with the SanDisk Memory Zone app.(5). Non-Operating Temperature -20°C to 85°C
const fs = require('node:fs');

fs.cpSync(sourcePath, destinationPath, {
  recursive: true,
  dereference: true,
});

The paths in this example are variables in your program; replace them with the source and destination you intend to copy. The dereference option requests that Node follow symlinks when copying. recursive controls copying a directory tree; it does not enable dereferencing by itself.

Check what happened before changing the copy

  1. Confirm the runtime: run node --version in the same environment that performs the copy. Node.js added fs.cpSync in v16.7.0; it ceased to be experimental in v22.3.0, according to the API documentation.
  2. Inspect the literal options: verify that the call actually passes dereference: true and, when copying a directory, recursive: true. Check wrappers or helper functions that may construct the options object.
  3. Inspect the link and its target: determine whether the source link is relative or absolute, where it resolves before copying, and where that same link resolves from the destination. A preserved relative link may resolve differently when the directory layout changes; an absolute link can continue pointing to its original location.
  4. Check the destination contents: determine whether the destination entry is itself a symlink or a regular file or directory. This distinguishes preserving a link from copying its target.

Choose whether the destination should preserve links

Desired result Setting Effect
Keep the symlink dereference: false (the documented default) The destination retains a link rather than copying the target.
Copy the target through the symlink dereference: true Requests that Node follow the symlink when copying.

verbatimSymlinks is a different option. The API documents its default as false; it controls whether path resolution for symlinks is skipped. It is not a substitute for dereference: true.

Rank #2
Sandisk 1TB Portable SSD, Up to 800MB/s Read Speeds, Black (Old Model) | External Solid State Drive, Compatible with Laptops & Tablets, Up to 2M Drop Protection, USB 3.2 Gen 2, USB-C to USB-A Cable
  • Solid state performance with up to 800MB/s read speeds in a portable drive. (Based on internal testing; performance may be lower depending on host device, interface, usage conditions and other factors. 1MB=1,000,000 bytes.)
  • Back up your content and memories on a storage solution that fits seamlessly into your mobile lifestyle.
  • Take it with you on your adventures—up to two-meter drop protection means this durable drive can take a beating. (Based on internal testing.)
  • Secure it to your belt loop or backpack for extra peace of mind thanks to the tough rubber hook.
  • From Sandisk, a brand professional photographers trust to take on assignments.

If dereference: true still leaves a link

A report in Node.js issue #59168 describes a caller on Node v22.17 seeing a destination symlink despite using { dereference: true, recursive: true }. That is a version-specific report, not proof that every v22.17 copy behaves that way or that it explains this case. The report does not establish a resolved status or affected-version range.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you can reproduce the result with those options, record the exact Node version, source and destination layout, symlink type and resolved target, and a minimal copy example. Those details help distinguish an option or layout mismatch from a runtime-specific problem.

Rank #3
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400) | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Do not confuse filesystem copying with module-loader flags

Node’s --preserve-symlinks and --preserve-symlinks-main flags affect module loading and path resolution; they do not configure fs.cpSync and will not make a filesystem copy follow symlink targets. The Node.js CLI documentation also warns that loading linked native modules from multiple locations can cause them to be treated as separate modules and fail to load. Consider these flags only when diagnosing module-resolution behavior, not as a repair for copied links.

Quick Recap

Bestseller No. 3
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400) | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400) | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$129.99
SaleBestseller No. 4
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model | External Solid State Drive, IP65 Water & Dust Resistant, Up to 3M Drop Protection, 256-bit AES Encryption, USB-C 3.2 Gen 2
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model | External Solid State Drive, IP65 Water & Dust Resistant, Up to 3M Drop Protection, 256-bit AES Encryption, USB-C 3.2 Gen 2
IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.; POCKET-SIZED – fits easily in pockets and small bags.
$249.99
Bestseller No. 5
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$219.99
Best Value
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
Rank #4
Sale
Sandisk 1TB Extreme Portable SSD, Up to 2000MB/s Transfer Speeds-New Model | External Solid State Drive, IP65 Water & Dust Resistant, Up to 3M Drop Protection, 256-bit AES Encryption, USB-C 3.2 Gen 2
  • NEARLY 2X FASTER THAN OUR PREVIOUS GENERATION(8) – move 1,000 high-res photos in under 60 seconds(6) with up to 2000MB/s transfer speeds(2).
  • IP65 RATING AND UP TO 3M DROP PROTECTION(3) – protects against spills and drops.
  • POCKET-SIZED – fits easily in pockets and small bags.
  • SPACE TO OWN YOUR AI CONTENT – speed and capacity to download your high-res clips and photo edits.
  • 256-BIT AES ENCRYPTION(4) – helps keep private files secure with password protection.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.