这不是我能在所有 Mac 上重现的错误,昨天我能够在另一台笔记本电脑上运行这个程序,没有问题,而且这是我在多个位置尝试执行多个任务时遇到的错误,但都失败了
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
我第一次注意到这一点是在尝试通过 npm 安装 phantomjs 时:
$ sudo npm install -g phantomjs
/usr/local/bin/phantomjs -> /usr/local/lib/node_modules/phantomjs/bin/phantomjs
> [email protected] install /usr/local/lib/node_modules/phantomjs
> node install.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
node.js:815
var cwd = process.cwd();
^
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:815:23)
at startup (node.js:58:13)
at node.js:906:3
npm ERR! Darwin 13.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "phantomjs"
npm ERR! node v0.10.32
npm ERR! npm v2.0.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the phantomjs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls phantomjs
npm ERR! There is likely additional logging output above.
从 node.js 安装 selenium-standalone 包时也会出现类似的问题:
$ sudo npm install -g selenium-standalone
/usr/local/bin/start-selenium -> /usr/local/lib/node_modules/selenium-standalone/bin/start-selenium
> [email protected] install /usr/local/lib/node_modules/selenium-standalone
> node install.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
node.js:815
var cwd = process.cwd();
^
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:815:23)
at startup (node.js:58:13)
at node.js:906:3
这似乎表明它与任何特定的 node.js 包无关,但是其他包安装良好(例如 grunt-cli)
最后,在寻找答案的过程中,我还发现了一些存在问题但无法解决问题的东西:
- 通过磁盘实用程序修复了我的硬盘上的权限,发现并修复了问题
- 重新启动进入恢复模式并修复了我的磁盘,该磁盘也存在问题
- sudo /usr/libexec/locate.updatedb 有同样的问题。有人建议启用 root 权限并运行它。这使得该命令可以正确运行,并且后续运行不再出现相同的错误。但是,尝试使用 npm 进行同样的操作并没有帮助
我不确定还有什么原因导致这个问题。
答案1
经过进一步搜索,我最终找到了这里有可行的答案我需要 npm install 时使用 --unsafe-perm 标志,这样才能正确安装无法正常工作的软件包
答案2
遇到了同样的问题。
/usr/local/bin/cordova -> /usr/local/lib/node_modules/cordova/bin/cordova
/usr/local/bin/ionic -> /usr/local/lib/node_modules/ionic/bin/ionic
> [email protected] install /usr/local/lib/node_modules/ionic/node_modules/node-sass
> node scripts/install.js
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
path.js:424
var path = (i >= 0) ? arguments[i] : process.cwd();
^
Error: EACCES: permission denied, uv_cwd
at Error (native)
at Object.posix.resolve (path.js:424:50)
at startup (node.js:96:32)
at node.js:968:3
npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "cordova" "ionic"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node scripts/install.js'.
npm ERR! This is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs node-sass
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls node-sass
npm ERR! There is likely additional logging output above.
使用命令:
sudo npm install --unsafe-perm -g cordova ionic
对我有用。