Skip to content

symlinkSync not working on Windows 10 #22208

@JonWallsten

Description

@JonWallsten
  • Version: 10.8.0
  • Platform: Windows 10 64-bit
  • Subsystem:

I'm unable to create a symbolic link with fs.symlinkSync, Node gives me the following error:
Error: EEXIST: file already exists, symlink

I have also tried running it with an elevated prompt without luck. Check all top result on Google. No luck.

//symlink.js
const fs = require('fs');
const path = require('path');

const origin = 'C:\\Users\\<masked>\\repo\\<masked>\\node_modules\\.bin\\tslint.cmd'; // Confirmed that it exists by "Windows Run"
const target = 'C:\\Users\\<masked>\\repo\\<masked>\\packages\\web-app-edit\\node_modules\\.bin\\tslint.cmd'; // Folder exists but file doesn't. Confirmed by code checks.

function ensureDirectoryExistence (filePath) {
    const dir = path.dirname(filePath);
    if (fs.existsSync(dir)) {
        return true;
    }
    ensureDirectoryExistence(dir);
    fs.mkdirSync(dir);
}

console.log('Symlink: ', target, origin);
if (!fs.existsSync(target) && fs.existsSync(origin)) {
    ensureDirectoryExistence(target);
    fs.symlinkSync(target, origin, 'file');
} else {
    console.warn('Symlink already exists. Target: ', target);
}
> node ./build-tools/symlink.js

Symlink:  C:\Users\<masked>\repo\<masked>\packages\web-app-edit\node_modules\.bin\tslint.cmd C:\Users\<masked>\repo\<masked>\node_modules\.bin\tslint.cmd
fs.js:113
    throw err;
    ^

Error: EEXIST: file already exists, symlink 'C:\Users\<masked>\repo\<masked>\packages\web-app-edit\node_modules\.bin\tslint.cmd' -> 'C:\Users\<masked>\repo\<masked>\node_modules\.bin\tslint.cmd'
    at Object.symlinkSync (fs.js:869:3)
    at Object.<anonymous> (C:\Users\<masked>\repo\<masked>\build-tools\symlink.js:19:8)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:266:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! web@ jon: `node ./build-tools/symlink.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the web@ jon script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<masked>\AppData\Roaming\npm-cache\_logs\2018-08-09T11_30_10_032Z-debug.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions