【问题标题】:NPM install doesn't install all components, node-gyp failsNPM install 没有安装所有组件,node-gyp 失败
【发布时间】:2015-11-02 04:07:27
【问题描述】:

我使用的是 ubuntu server 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 重建,输出如下:

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 进行安装,但没有任何效果。 这已经到了我超越绝望的地步。 任何人都可以帮助我吗?非常感谢...

【问题讨论】:

  • 您的node-gyp rebuild 不适用于预发布版本。所以要么获取最新的稳定版本(根据他们的站点是 12.2),要么运行node-gyp rebuild --nodedir /path/to/install/node/to,然后将其添加到您的路径中。此外,有一次您说您运行了sudo npm install,但进一步赞扬您省略了sudo。确保您始终如一地运行命令。

标签: node.js mongodb ubuntu mongoose npm


【解决方案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 目录下的项目中安装你的模块,你将能够在每个项目中使用不同的版本。

【讨论】:

    【解决方案2】:

    在依赖项中,删除 mongodb。猫鼬将在其中安装驱动程序。

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

    然后做

    sudo npm unistall mongodb
    sudo npm cache clean
    sudo npm install
    

    如果问题仍然存在,那么做

    sudo apt-get install build-essential
    

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

    【讨论】:

      【解决方案3】:

      这个问题在我身上发生过几次。

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

      npm cache clean
      npm i
      

      不要使用sudo!需要清除全局 npm 箱的缓存,而不是本地的,而且,如果您将 nvm 作为普通用户使用(对于本地和全局包),则不需要

      【讨论】:

        猜你喜欢
        • 2016-02-27
        • 2020-01-05
        • 2020-09-11
        • 1970-01-01
        • 2020-03-19
        • 2018-05-19
        • 1970-01-01
        • 2012-08-20
        • 1970-01-01
        相关资源
        最近更新 更多