模块目录下npm install -g安装的依赖库路径疑问
发布于 9 年前 作者 JunejaTung 9535 次浏览 最后一次编辑是 8 年前 来自 问答

[root@wlan-cloudserver10 wlanpub]# npm install -g \

kerberos@0.0.15 install /usr/local/lib/node_modules/wlanpub/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos (node-gyp rebuild) || (exit 0)

gyp WARN EACCES user “wlanuser” does not have permission to access the dev dir "/root/.node-gyp/0.12.6" gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/wlanpub/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/.node-gyp" gyp WARN install got an error, rolling back install gyp WARN install got an error, rolling back install gyp ERR! configure error gyp ERR! stack Error: node-v0.12.6.tar.gz local checksum c2ed197677792b9b3c54dd0faf28afaea2cf631b594365c962454138b9c2eeb8 not match remote 7a3b5ac351973a9dee8edbf0684bc8d0dea44b231e42274ffb008141ffa19ad2 gyp ERR! stack at deref (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:307:20) gyp ERR! stack at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:348:13) gyp ERR! stack at IncomingMessage.emit (events.js:129:20) gyp ERR! stack at _stream_readable.js:908:16 gyp ERR! stack at process._tickCallback (node.js:355:11) gyp ERR! System Linux 2.6.32-504.el6.x86_64 gyp ERR! command “node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” "rebuild" gyp ERR! cwd /usr/local/lib/node_modules/wlanpub/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos gyp ERR! node -v v0.12.6 gyp ERR! node-gyp -v v2.0.1 gyp ERR! not ok wlanpub@0.1.1 /usr/local/lib/node_modules/wlanpub ├── uuid@2.0.1 ├── redis@0.12.1 ├── amqp@0.2.4 (lodash@1.3.1) └── mongoose@4.1.12 (regexp-clone@0.0.1, sliced@0.0.5, muri@1.0.0, hooks-fixed@1.1.0, mpromise@0.5.4, kareem@1.0.1, mpath@0.1.1, async@0.9.0, ms@0.1.0, bson@0.4.19, mquery@1.6.3, mongodb@2.0.46)

疑问: 我在模块wlanpub目录下执行npm install -g,意图将依赖库直接安装在 全局路径下即/usr/local/lib/node_modules/,这样安装的依赖库也可以供其他模块项目使用,但实际情况是其在全局目录下加了一级模块目录/usr/local/lib/node_modules/wlanpub/node_modules/,为什么会这样? 我不想通过npm install直接装在项目模块目录下(因为只能当前项目用)

附:1、linux环境 [root@wlan-cloudserver10 webserver2]# node -v v0.12.6 [root@wlan-cloudserver10 webserver2]# npm -v 2.11.2 [root@wlan-cloudserver10 webserver2]# npm root -g /usr/local/lib/node_modules [root@wlan-cloudserver10 webserver2]#

2、package.json { “name”: “wlanpub”, “version”: “0.1.1”, “description”: “H3C WLAN Cloud-plat public module”, “main”: “wlanpub.js”, “scripts”: { “test”: “echo “Error: no test specified” && exit 1” }, “keywords”: [ “wlanpub” ], “repository”: { “type”: “git”, “url”: “git://github.com/JunejaTung/wlanpub.git” }, “homepage”: “https://github.com/JunejaTung/wlanpub”, "_id": “wlanpub@0.1.1”, “dependencies”: { “amqp”: “~0.2.4”, “uuid”: “~2.0.1”, “redis”: “~0.12.1”, “mongoose”: “~4.1.0” }, “author”: “Juneja”, “license”: “ISC” }

3 回复

为啥要加-g

@reverland -g是说安装到全局路径下,主要目的是想在项目模块文件下将依赖库安装到全局路径下,而不是项目模块的路径下;这样多个不同项目模块能共用依赖库,没必要每个项目下都去安装一份。 但我实践的情况是其在全局路径下又创建了一个 项目名/node_modules/ 的目录来放依赖库

没人碰到这个现象嘛?虽然可以npm intall解决,但我还是奇怪为啥加了-g没有达到预期结果

回到顶部