简体   繁体   English

猫鼬安装-无法验证第一个证书

[英]Mongoose install - unable to verify the first certificate

I've read various answers about this error but I cannot get rid of it, when trying to install mongoose with npm install mongoose I get the following error: 我读过有关这个错误的各种答案,但要安装与猫鼬 ,当我无法摆脱它, npm install mongoose我得到以下错误:

vagrant@mean:/var/www/html/test$ npm install mongoose --save-dev
-
> kerberos@0.0.14 install /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> (node-gyp rebuild) || (exit 0)

gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: unable to verify the first certificate
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1000:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:567:8)
gyp ERR! System Linux 3.13.0-55-generic
gyp ERR! command "/home/vagrant/.nvm/versions/node/v4.1.1/bin/node" "/home/vagrant/.nvm/versions/node/v4.1.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
gyp ERR! node -v v4.1.1
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
mongoose@4.1.8 node_modules/mongoose
├── async@0.9.0
├── hooks-fixed@1.1.0
├── regexp-clone@0.0.1
├── mpromise@0.5.4
├── mpath@0.1.1
├── muri@1.0.0
├── ms@0.1.0
├── sliced@0.0.5
├── kareem@1.0.1
├── bson@0.4.12
├── mquery@1.6.3 (debug@2.2.0, bluebird@2.9.26)
└── mongodb@2.0.42 (es6-promise@2.1.1, readable-stream@1.0.31, mongodb-core@1.2.10)

I am running a new vagrant box ubuntu/trusty64 behind a corporate SSL proxy, here are my proxy configurations: 我在公司SSL代理后面运行一个新的vagrant框ubuntu/trusty64 ,这是我的代理配置:

envvars 环境变量

$HTTPS_PROXY=http://user:pwd@ip:port
$HTTP_PROXY=http://user:pwd@ip:port

~/.npmrc 〜/ .npmrc

https-proxy=http://user:pwd@ip:port
proxy=http://user:pwd@ip:port
ca=/etc/ssl/certs/acme.pem
cafile=/etc/ssl/certs/acme.pem

the certificate is trusted, both npm & curl works great 证书是受信任的,npm和curl都很好用

how did I try to fix the error 我如何尝试解决该错误

sudo apt-get install build-essential
npm install -g node-gyp

The --verbose error log --verbose错误日志

npm info install kerberos@0.0.14

> kerberos@0.0.14 install /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> (node-gyp rebuild) || (exit 0)

gyp info it worked if it ends with ok
gyp verb cli [ '/home/vagrant/.nvm/versions/node/v4.1.1/bin/node',
gyp verb cli   '/home/vagrant/.nvm/versions/node/v4.1.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild' ]
gyp info using node-gyp@3.0.3
gyp info using node@4.1.1 | linux | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/bin/python2
gyp verb check python version `python2 -c "import platform; print(platform.python_version());"` returned: "2.7.6\n"
gyp verb get node dir no --target version specified, falling back to host node version: 4.1.1
gyp verb command install [ '4.1.1' ]
gyp verb install input version string "4.1.1"
gyp verb install installing version: 4.1.1
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version not already installed, continuing with install 4.1.1
gyp verb ensuring nodedir is created /home/vagrant/.node-gyp/4.1.1
gyp verb created nodedir /home/vagrant/.node-gyp/4.1.1
gyp http GET https://nodejs.org/dist/v4.1.1/node-v4.1.1-headers.tar.gz
gyp verb download using proxy url: "http://usr:pwd@ip:port/"
gyp WARN install got an error, rolling back install
gyp verb command remove [ '4.1.1' ]
gyp verb remove using node-gyp dir: /home/vagrant/.node-gyp
gyp verb remove removing target version: 4.1.1
gyp verb remove removing development files for version: 4.1.1
gyp ERR! configure error
gyp ERR! stack Error: unable to verify the first certificate
gyp ERR! stack     at Error (native)
gyp ERR! stack     at TLSSocket.<anonymous> (_tls_wrap.js:1000:38)
gyp ERR! stack     at emitNone (events.js:67:13)
gyp ERR! stack     at TLSSocket.emit (events.js:166:7)
gyp ERR! stack     at TLSSocket._finishInit (_tls_wrap.js:567:8)
gyp ERR! System Linux 3.13.0-55-generic
gyp ERR! command "/home/vagrant/.nvm/versions/node/v4.1.1/bin/node" "/home/vagrant/.nvm/versions/node/v4.1.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/html/test/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
gyp ERR! node -v v4.1.1
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok

Most likely your proxy server changes SSL certificate (to be able to sniff your traffic), making the certificate invalid. 您的代理服务器很可能会更改SSL证书(以便能够嗅探您的流量),从而使证书无效。 To workaround this add another environment variable: NODE_TLS_REJECT_UNAUTHORIZED=0 要解决此问题,请添加另一个环境变量: NODE_TLS_REJECT_UNAUTHORIZED=0

Be cautious though, because this changes global NodeJS behavior, forcing it to ignore any unauthorized certificates. 但是请务必谨慎,因为这会更改全局NodeJS行为,从而迫使其忽略任何未经授权的证书。

Nice, thank @Max Shmelev 很好,谢谢@Max Shmelev

With Windows: set NODE_TLS_REJECT_UNAUTHORIZED=0 对于Windows: set NODE_TLS_REJECT_UNAUTHORIZED=0

then npm install again! 然后再次npm install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM