You have to set the target directory to be relative or absolute:
fs.symlinkSync('../client', 'build/client', 'dir');
I confirmed the behavior to be the same when using the same directory structure and path names in symlink(2)
:
// Directory structure
build/
client/
–> index.js
// Fails
$ ln -s client build/client
$ stat build/client/index.js
stat: build/client/index.js: stat: Too many levels of symbolic links
// Works
$ ln -s ../client build/client
$ stat build/client/index.js
stat: <outputs file stats>
The target HAS to be relative or absolute. Even though in node we know client
will resolve to the cwd
in a require call or even an fs.read/write
, this is not the case in fs.symlink
which is an alias for symlink(2)
.
Update:
My reasoning is confirmed by the Unix/Linux guys. See this post for details.