NPM install 在安装 express 时出现错误

Posted

技术标签:

【中文标题】NPM install 在安装 express 时出现错误【英文标题】:NPM install giving error installing express 【发布时间】:2013-07-02 17:15:12 【问题描述】:

当我发出命令npm install express 时,它会引发以下错误。在ubuntu机器上

gaurav@gaurav-Mini-Monster:~/TestScripts$ sudo npm install -g express
npm ERR! error installing express@3.3.3 Error: Unsupported
npm ERR! error installing express@3.3.3     at checkEngine (/usr/local/lib/node_modules/npm/lib/install.js:493:14)
npm ERR! error installing express@3.3.3     at Array.0 (/usr/local/lib/node_modules/npm/node_modules/slide/lib/bind-actor.js:15:8)
npm ERR! error installing express@3.3.3     at LOOP (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:15:13)
npm ERR! error installing express@3.3.3     at chain (/usr/local/lib/node_modules/npm/node_modules/slide/lib/chain.js:20:4)
npm ERR! error installing express@3.3.3     at installOne_ (/usr/local/lib/node_modules/npm/lib/install.js:470:3)
npm ERR! error installing express@3.3.3     at installOne (/usr/local/lib/node_modules/npm/lib/install.js:411:3)
npm ERR! error installing express@3.3.3     at /usr/local/lib/node_modules/npm/lib/install.js:347:9
npm ERR! error installing express@3.3.3     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:35
npm ERR! error installing express@3.3.3     at Array.forEach (native)
npm ERR! error installing express@3.3.3     at /usr/local/lib/node_modules/npm/node_modules/slide/lib/async-map.js:54:11
npm ERR! error rolling back express@3.3.3 Error: UNKNOWN, Unknown error '/usr/local/lib/node_modules/express'
npm ERR! Unsupported
npm ERR! Not compatible with your version of node/npm: connect@2.8.3
npm ERR! Required: "node":">= 0.8.0"
npm ERR! Actual:   "npm":"1.0.106","node":"0.5.11-pre"
npm ERR! 
npm ERR! System Linux 3.2.0-48-generic-pae
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /home/gaurav/TestScripts
npm ERR! node -v v0.5.11-pre
npm ERR! npm -v 1.0.106
npm ERR! code ENOTSUP
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/gaurav/TestScripts/npm-debug.log
npm not ok

我也试过

sudo npm install express
npm install -g express
sudo npm install -g express

没有任何作用。

【问题讨论】:

你的 Ubuntu 版本是多少? 【参考方案1】:

Node 非常容易手动安装。我也喜欢这样做,因为切换版本真的很容易。

这也很棒,因为您不需要将一些外部包存储库添加到apt,并且您不必在节点发布新版本时等待这些存储库更新。您可以在更新发布后立即获得。

# make a `~/.nodes/ folder
mkdir -p ~/.nodes && cd ~/.nodes

# download the binaries from nodejs.org
# in this case, here's the linux version
curl -O http://nodejs.org/dist/v0.10.12/node-v0.10.12-linux-x64.tar.gz

# extract
tar -xzf node-v0.10.12-linux-x64.tar.gz

# rename folder to 0.10.12
mv node-v0.10.12-linux-x64 0.10.12

# create a `current` symlink
ln -s 0.10.12 current

# prepend ~/.nodes/bin to your path
# you'll want to save this in ~/.bashrc or ~/.zshrc or something
export PATH="~/.nodes/current/bin:$PATH"

# cleanup
rm ~/.nodes/node-v0.10.12-linux-x64.tar.gz

最好的部分是您可以为任何其他版本的节点重复该模式,随时更改current 符号链接以切换您正在运行的版本,一切顺利

% node --version
v0.10.12

% npm --version
1.2.32

# switch versions to (e.g.) 0.10.5
% cd ~/.nodes && rm current && ln -s 0.10.5 current

% node --version
v0.10.5

% npm --version
1.2.18

编写可执行脚本时的附加指针

制作可执行文件

% touch ~/somefile && chmod +x ~/someifle && nano ~/somefile

文件内容

#!/usr/bin/env node
console.log(process.version);

运行它

% ./somefile
v0.10.12

【讨论】:

谢谢@naomik。我使用相同的方法使用源升级节点。问题解决了。经验教训:)【参考方案2】:

您正在运行一个太旧的nodenpm 版本。您有非常过时的节点 v0.5。升级到 node v0.10 一切正常。

Ubuntu 的现代 node.js 版本可通过 this PPA from Chris Lea 获得

安装:

sudo apt-get install python-software-properties
sudo add-apt-repository --yes ppa:chris-lea/node.js
sudo apt-get install nodejs

更新

看起来您的旧版本节点安装在/usr/local/bin/node。 Chris Lea PPA 的新版本将在 /usr/bin/node。因此,要验证一切正常,请执行以下操作:

/usr/bin/npm --version #Should be approx 1.2
/usr/bin/node --version #should be approx v0.10
/usr/bin/npm install -g express

你应该卸载本地节点,或者修复你的 PATH:

export PATH=/usr/bin:$PATH

【讨论】:

我已正确识别出您的问题。如果您不打算付出更多的努力来帮助我们帮助您,那么您不应该得到我们的帮助。 @PeterLyons 起初你的评论对我来说似乎有点生气,但我已经更好地阅读了这个问题和你的答案,你是完全正确的。 sudo apt-get install python-software-properties -> 这个命令运行良好。 add-apt-respository 命令也很有效。但是 sudo apt-get install nodejs 执行但仍然显示 node --version to v0.5.11-pre 查看我的更新。您现在既有旧版本又有新版本,需要确保使用新版本。

以上是关于NPM install 在安装 express 时出现错误的主要内容,如果未能解决你的问题,请参考以下文章

npm中package-lock.json的作用:npm install安装时使用

出现错误,错误:npm install 后找不到模块“express”

我正在尝试使用“npm install mongodb”在 Windows 8 机器上为节点 js express 安装 MongoDB,出现以下错误

express+session实现简易身份认证

npm 常用指令

npm常用命令