gpt4 book ai didi

node.js - Linux 上需要 ('os' ).homedir() 错误

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

当我在 linux 中使用 sudo 执行这个单行脚本时,我收到一个错误,但在我的 mac osx 上却没有。

var homedir =require('os').homedir();

错误:

testhomedir.js:1
quire, module, __filename, __dirname) { var homedir = require('os').homedir();
^

TypeError: undefined is not a function

at Object.<anonymous> (/home/marco/test/testhomedir.js:1:91)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

有什么想法吗?

最佳答案

正如罗伯特在评论中指出的那样,我的 sudo 使用了与普通用户不同的 Node 版本。

这个stackoverflow post为我提供了问题的答案

停止所有使用 Node 的服务并发出命令

n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

这会将事件使用的 Node 版本复制到全局使用的文件夹中。

关于node.js - Linux 上需要 ('os' ).homedir() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38147100/

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