Question

> fs.symlinkSync('client', 'build/client', 'dir')

> fs.statSync('build/client/index.js')
Error: ELOOP, too many symbolic links encountered 'build/client/index.js'
    at Object.fs.lstatSync (fs.js:679:18)
    at repl:1:5
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)

what am i doing wrong?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top