NPM安装没有安装所有组件,node-gyp失败

时间:2015-04-05 18:30:35

标签: node.js mongodb ubuntu mongoose npm

我使用的是ubuntu服务器14.04.1 LTS,我相信它是一台x32机器

尝试运行我的nodejs实例时出现错误

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } js-bson: Failed to load c++ bson extension, using pure JS version

不要链接与上述问题相关的答案。问题不在于它无法加载。 它还没有安装。这是我的package.json依赖项:

"dependencies": {
    "express": "*",
    "socket.io": "*",
    "mongodb": "*",
    "mongoose": "*"
}

当我运行 sudo npm install (npm是最新版本)时,我得到以下内容:

npm WARN package.json forum@0.0.1 No description
npm WARN package.json forum@0.0.1 No repository field.
npm WARN package.json forum@0.0.1 No README data
npm WARN engine express@4.12.3: wanted: {"node":">= 0.10.0"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})
npm WARN engine mongoose@4.0.1: wanted: {"node":">=0.6.19"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})
(...)
npm WARN engine options@0.0.6: wanted: {"node":">=0.4.0"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})
-
> ws@0.5.0 install /usr/share/nginx/www/node_modules/socket.io/node_modules/engine.io/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

npm WARN engine hooks-fixed@1.0.1: wanted: {"node":">=0.4.0"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})
(...)
npm WARN engine base64-arraybuffer@0.1.2: wanted: {"node":">= 0.6.0"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})

> kerberos@0.0.10 install /usr/share/nginx/www/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)

npm WARN engine bson-ext@0.1.0: wanted: {"node":">=0.8.19"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})
(...)
npm WARN engine tinycolor@0.0.1: wanted: {"node":">=0.4.0"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})

> ws@0.4.31 install /usr/share/nginx/www/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

npm WARN engine bson@0.2.21: wanted: {"node":">=0.6.19"} (current: {"node":"0.13.0-pre","npm":"2.7.5"})

> bson-ext@0.1.0 install /usr/share/nginx/www/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> kerberos@0.0.10 install /usr/share/nginx/www/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> bson@0.2.21 install /usr/share/nginx/www/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> bson@0.3.1 install /usr/share/nginx/www/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)

实际上,在node_modules子文件夹中找不到这些文件夹(bson,kerberos,ws)。所以它确实 MODULE_NOT_FOUND

我尝试运行 npm update ,什么都不做,总是重复相同的输出。 我尝试了 node-gyp rebuild ,这是输出:

gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.3
gyp info using node@0.13.0-pre | linux | ia32
gyp ERR! configure error 
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack     at install (/usr/local/lib/node_modules/node-gyp/lib/install.js:66:16)
gyp ERR! stack     at Object.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/node-gyp/lib/node-gyp.js:66:37)
gyp ERR! stack     at getNodeDir (/usr/local/lib/node_modules/node-gyp/lib/configure.js:152:20)
gyp ERR! stack     at /usr/local/lib/node_modules/node-gyp/lib/configure.js:95:9
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:723:7)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at maybeClose (child_process.js:1000:16)
gyp ERR! stack     at Socket.<anonymous> (child_process.js:1168:11)
gyp ERR! stack     at Socket.emit (events.js:107:17)
gyp ERR! stack     at Pipe.close (net.js:461:12)
gyp ERR! System Linux 3.13.0-48-generic
gyp ERR! command "node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /usr/share/nginx/www
gyp ERR! node -v v0.13.0-pre
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 

我尝试使用带有-g的node-gyp进行安装,但没有任何效果。 这已经达到了我超越绝望的程度。 有人可以帮我吗?非常感谢你......

3 个答案:

答案 0 :(得分:1)

尝试在依赖项中添加特定的稳定版和兼容版:

"dependencies": {
    "express": "^4.13.3",
    "mongodb": "^2.0.47",
    "mongoose": "^4.2.3",
    "socket.io": "^1.3.7"
}

如果您在项目中运行npm install,则不应将npm作为sudo运行。如果你不这样做npm应该在node_modules目录中的项目中安装你的模块,你就可以在每个项目中使用不同的版本。

答案 1 :(得分:0)

在依赖项中,删除mongodb。 mongoose会在其中安装驱动程序。

"dependencies": {
    "express": "*",
    "socket.io": "*",       
    "mongoose": "*"
}

然后做

sudo npm unistall mongodb
sudo npm cache clean
sudo npm install

如果问题仍然存在,请执行

sudo apt-get install build-essential

另外,如果您不是root用户,请始终在sudo下运行命令。

答案 2 :(得分:0)

这个问题有时发生在我身上。

  

到目前为止,清除npm缓存就足够了:

Mock.Get(mock)
  

请勿使用npm cache clean npm i !需要清除全局npm容器的缓存,而不是本地缓存,并且,如果您使用nvm作为普通用户(对于本地和全局包),则需要清除缓存