关于yarn add bcrypt安装失败的问题

前言

今天在使用bcrypt进行加密时出现了一点问题,忽然想起来,之前安装cypress时也出现这个问题,看来是和我的python包有关系。

问题描述

首先,在安装bcrypt时,总是会卡住:

bcrypt...

或者直接报错:

G:\nodejs\moviesite\node_modules\bcrypt>if not defined npm_config_node_gyp (node
"D:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\
node-gyp\bin\node-gyp.js" rebuild )  else (rebuild)
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT
HON env variable.
gyp ERR! stack     at failNoPython (D:\Program Files\nodejs\node_modules\npm\nod
e_modules\node-gyp\lib\configure.js:103:14)
gyp ERR! stack     at D:\Program Files\nodejs\node_modules\npm\node_modules\node
-gyp\lib\configure.js:64:11
gyp ERR! stack     at FSReqWrap.oncomplete (evalmachine.<anonymous>:95:15)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "D:\\Program Files\\nodejs\\node_modules\\npm\\node_modu
les\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd G:\nodejs\moviesite\node_modules\bcrypt
gyp ERR! node -v v0.12.2
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "D:\\Program Files\\nodejs\\\\node.exe" "D:\\Program Files\\nodejs
\\node_modules\\npm\\bin\\npm-cli.js" "install" "bcrypt" "--save"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE

在一番研究过后,我觉得很可能是python版本的问题,因为为了能够顺利进行react-native开发,我主要使用python2进行开发 ,然而马上五天就寿终正寝的python2会不会是这个报错的罪魁祸首呢?

于是我安装了python3,并把它设置为主要版本的python解释器。

然而还是老样子。

解决

最后,因为bcrypt是python包开发的,在使用npm的时候,在windows下需要安装一个工具:

npm install --global --production windows-build-tools

不知道这个在生产环境中该怎么办?

这个包相当大,有3G左右的样子,安装之后bcrypt就可以成功添加到项目依赖中了.

发布了346 篇原创文章 · 获赞 330 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43870742/article/details/103697926
Add