fs.symlink给我ELOOP错误

> 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) 

我究竟做错了什么?

您必须将目标目录设置为相对或绝对:

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

我确认在symlink(2)使用相同的目录结构和path名时,其行为是相同的:

 // 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> 

目标是相对的或绝对的。 即使在节点中,我们知道client将在require调用或者fs.read/writeparsing为cwd ,但在fs.symlink这不是一个symlink(2)的别名。

更新:

我的推理被Unix / Linux家伙证实。 详情请看这个post 。