gpt4 book ai didi

node.js - fs.symlink 给我 ELOOP 错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:20 26 4
gpt4 key购买 nike

> 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) 中使用相同的目录结构和路径名时,行为是相同的:

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

目标必须是相对的或绝对的。即使在 Node 中,我们知道 client 将解析为 require 调用中的 cwd,甚至是 fs.read/write,但 fs.symlink 中的情况并非如此,它是 symlink(2) 的别名。

更新:

我的推理得到了 Unix/Linux 人员的证实。 See this post for details .

关于node.js - fs.symlink 给我 ELOOP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20642529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com