Npm 安装失败,“无法在 wd 中运行"; [英] Npm install failed with "cannot run in wd"

查看:28
本文介绍了Npm 安装失败,“无法在 wd 中运行";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新的 Ubuntu 12.04 实例上设置我的节点环境,并且已经安装了 Node 0.8.14,但是当我尝试运行 npm install 时遇到了问题.所以当我尝试 npm install 时,它说我需要以 root 或管理员身份运行它:

I am trying to get my node environment set up on a new Ubuntu 12.04 instance, with Node 0.8.14 already installed, but I ran into problems when I try to run npm install. So when I try npm install, it says that I need to run it as root or adminisrator:

Error: EACCES, mkdir '/usr/local/lib/node_modules/coffee-script'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/coffee-script']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/coffee-script',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/coffee-script',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ 'DirWriter._create                 (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:297:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

但是当尝试以 sudo 运行它时,它会显示以下内容:

But when try to run it as sudo, it says the following:

npm WARN cannot run in wd PackNodeDev@0.0.1-166 npm install -g coffee-script node-gyp (wd=/home/ubuntu/PackNode)

在我的 package.json 中,它包含以下脚本:

In my package.json, it contains the following scripts:

"scripts": {
    "preinstall": "npm install -g coffee-script node-gyp",
    "start": "node server.js",
    "test": "mocha --require should --compilers coffee:coffee-script --colors"
 },

其余的 devdependencies 是有效的,因为我一直在我自己的机器 (Mac) 上安装它有没有人知道为什么会这样?

The rest of devdependencies are valid since I have been installing it all right on my own machine (Mac) Does anyone have a clue why this is happening?

推荐答案

OP 这里,自从我第一次问这个问题以来,我对 node 有了更多的了解.尽管 Dmitry 的回答非常有帮助,但最终对我来说是安装具有正确权限的节点.

OP here, I have learned a lot more about node since I first asked this question. Though Dmitry's answer was very helpful, what ultimately did it for me is to install node with the correct permissions.

我强烈建议不要使用任何包管理器安装 node,而是自己编译它,使其驻留在具有正常权限的本地目录中.

I highly recommend not installing node using any package managers, but rather to compile it yourself so that it resides in a local directory with normal permissions.

本文提供了一个非常清晰的分步说明,说明了如何操作:

This article provides a very clear step-by-step instruction of how to do so:

https://www.digitalocean.com/community/tutorials/how-to-install-an-upstream-version-of-node-js-on-ubuntu-12-04

这篇关于Npm 安装失败,“无法在 wd 中运行";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆