npm 命令在 ubuntu 上不起作用 [英] npm command not working on ubuntu

查看:111
本文介绍了npm 命令在 ubuntu 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Ubuntu 14.04 上安装了 node 和 npm,当我尝试使用任何 npm 命令时,出现以下错误:

I installed node and npm on Ubuntu 14.04 and when I try to use any npm command, I get the following error:

/usr/local/lib/node_modules/npm/lib/config/cmd-list.js:113
module.exports.aliases = Object.assign({}, shorthands, affordances)
                            ^
TypeError: Object function Object() { [native code] } has no method 'assign'
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/cmd-list.js:113:33)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /usr/local/lib/node_modules/npm/lib/npm.js:37:17
at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/npm.js:471:3)
at Module._compile (module.js:456:26)

我是使用 node 的新手,我没有在网上找到任何解决此类错误的方法

I'm new to using node and I didn't find any solution to such an error online

推荐答案

您很可能正在运行旧版本的 node.js(使用 node -v 进行验证,在撰写本文时,最新的 lts 是 6.x).我想您尝试使用 apt-get install nodejs 或类似方法安装它.ubuntu 14 附带的软件包已过时,请按照 nodejs 下载页面 上的建议进行操作,并执行以下操作:

You are most likely running an old version of node.js (verify with node -v, at the time of writing this, the latest lts is 6.x). I suppose you tried to install it with apt-get install nodejs or similar. The packages shipped with ubuntu 14 are outdated, follow the advice on nodejs' download page instead, and do the following:

第一步,删除旧包:

sudo apt-get remove --purge nodejs

第 2 步,依次输入以下命令并跟随屏幕:

Step 2, type the following commands one after the other and follow the screen:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

现在您安装了一个允许 ES6 方法的 nodejs 版本,因为 Object.assign 就是其中之一

Now you have a version of nodejs installed that allows ES6 methods, as Object.assign is one of them

这篇关于npm 命令在 ubuntu 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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