如何在Windows 7上进行“npm install bcrypt”

9

我已经安装了node.js v6.9.1和npm版本4.1.2,并且已经在一些项目中使用了这个组合。

现在我想在我的项目中使用bcrypt npm包,但是安装失败了。

npm install bcrypt --save

我也尝试以管理员权限运行此命令,但结果还是失败了。

这是我得到的错误信息。

> bcrypt@1.0.2 install C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcry
pt
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcryp
t.js/releases/download/v1.0.2/bcrypt_lib-v1.0.2-node-v48-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.2 and node@6.9.1 (
node-v48 ABI) (falling back to source compile with node-gyp)

C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt>if not defined npm_c
onfig_node_gyp (node "C:\Users\ttheiner\AppData\Roaming\npm\node_modules\npm\bin
\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" clean )  else (node
"" clean )

C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt>if not defined npm_c
onfig_node_gyp (node "C:\Users\ttheiner\AppData\Roaming\npm\node_modules\npm\bin
\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" configure --fallback
-to-build --module=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt\l
ib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\tthei
ner\NodeProjects\authtest\node_modules\bcrypt\lib\binding )  else (node "" confi
gure --fallback-to-build --module=C:\Users\ttheiner\NodeProjects\authtest\node_m
odules\bcrypt\lib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path
=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt\lib\binding )
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 Object.failNoPython (C:\Users\ttheiner\AppData\Roaming\npm
\node_modules\npm\node_modules\node-gyp\lib\configure.js:454:19)
gyp ERR! stack     at Object.<anonymous> (C:\Users\ttheiner\AppData\Roaming\npm\
node_modules\npm\node_modules\node-gyp\lib\configure.js:480:16)
gyp ERR! stack     at C:\Users\ttheiner\AppData\Roaming\npm\node_modules\npm\nod
e_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:123:15)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ttheiner\\App
Data\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js"
 "configure" "--fallback-to-build" "--module=C:\\Users\\ttheiner\\NodeProjects\\
authtest\\node_modules\\bcrypt\\lib\\binding\\bcrypt_lib.node" "--module_name=bc
rypt_lib" "--module_path=C:\\Users\\ttheiner\\NodeProjects\\authtest\\node_modul
es\\bcrypt\\lib\\binding"
gyp ERR! cwd C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp.cmd configure --fallb
ack-to-build --module=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcryp
t\lib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\tt
heiner\NodeProjects\authtest\node_modules\bcrypt\lib\binding' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\Users\ttheiner\NodeP
rojects\authtest\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:106:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/chi
ld_process.js:226:5)
node-pre-gyp ERR! System Windows_NT 6.1.7601
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\tthe
iner\\NodeProjects\\authtest\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "in
stall" "--fallback-to-build"
node-pre-gyp ERR! cwd C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcryp
t
node-pre-gyp ERR! node -v v6.9.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok
Failed to execute 'node-gyp.cmd configure --fallback-to-build --module=C:\Users\
ttheiner\NodeProjects\authtest\node_modules\bcrypt\lib\binding\bcrypt_lib.node -
-module_name=bcrypt_lib --module_path=C:\Users\ttheiner\NodeProjects\authtest\no
de_modules\bcrypt\lib\binding' (1)
npm WARN authtest@1.0.0 No repository field.
npm WARN authtest@1.0.0 No license field.
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ttheiner\\AppDat
a\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "bcrypt" "--save"

npm ERR! node v6.9.1
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE

npm ERR! bcrypt@1.0.2 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@1.0.2 install script 'node-pre-gyp install --fallb
ack-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs bcrypt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\ttheiner\NodeProjects\authtest\npm-debug.log

问题似乎在于npm找不到预先构建的二进制文件,因此它尝试使用Python编译源代码(而我好像没有Python)。
我需要安装Python吗?如果是,你能告诉我正确的安装方法吗?bcrypt没有预先构建的版本是真的吗?
编辑:安装Python 2.7后,错误信息发生了变化...似乎它尝试使用MSBuild来编译一些C++代码。
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir var
iable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [C:\Users\ttheiner\NodeProject
s\authtest\node_modules\bcrypt\build\bcrypt_lib.vcxproj]
TRACKER : error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified. [C:\Users\ttheiner\NodeProjects\authtest\no
de_modules\bcrypt\build\bcrypt_lib.vcxproj]


gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\ttheiner\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:276:23)

gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ttheiner\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gy
p\\bin\\node-gyp.js" "build" "--fallback-to-build" "--module=C:\\Users\\ttheiner\\NodeProjects\\authtest\\node_modules\\bcrypt\\lib\\binding
\\bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=C:\\Users\\ttheiner\\NodeProjects\\authtest\\node_modules\\bcrypt\\lib\\binding
"
gyp ERR! cwd C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'node-gyp.cmd build --fallback-to-build --module=C:\Users\ttheiner\NodeProjects\authtest\no
de_modules\bcrypt\lib\binding\bcrypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bc
rypt\lib\binding' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\Users\ttheiner\NodeProjects\authtest\node_modules\node-pre-gyp\lib\util\compile.
js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:106:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:877:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
node-pre-gyp ERR! System Windows_NT 6.1.7601
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ttheiner\\NodeProjects\\authtest\\node_modules\\node-pre-gyp\\bi
n\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt
node-pre-gyp ERR! node -v v6.9.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok
Failed to execute 'node-gyp.cmd build --fallback-to-build --module=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt\lib\binding\b
crypt_lib.node --module_name=bcrypt_lib --module_path=C:\Users\ttheiner\NodeProjects\authtest\node_modules\bcrypt\lib\binding' (1)
npm WARN authtest@1.0.0 No repository field.
npm WARN authtest@1.0.0 No license field.
npm WARN Error: EPERM: operation not permitted, scandir 'C:\Users\ttheiner\NodeProjects\authtest\node_modules\dashdash\node_modules'
npm WARN     at Error (native)
npm WARN  { Error: EPERM: operation not permitted, scandir 'C:\Users\ttheiner\NodeProjects\authtest\node_modules\dashdash\node_modules'
npm WARN     at Error (native)
npm WARN   errno: -4048,
npm WARN   code: 'EPERM',
npm WARN   syscall: 'scandir',
npm WARN   path: 'C:\\Users\\ttheiner\\NodeProjects\\authtest\\node_modules\\dashdash\\node_modules' }
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\ttheiner\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "instal
l" "bcrypt" "--save"
npm ERR! node v6.9.1
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE

npm ERR! bcrypt@1.0.2 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@1.0.2 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs bcrypt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\ttheiner\NodeProjects\authtest\npm-debug.log

“Python 2.x”被列为npm上的明确依赖项,因此我怀疑您无法避免使用它。 - Aleksey Bilogur
奇怪的是,在安装了Python 2.7之后,错误发生了变化。请参见最新编辑。 - devnull69
1
请参阅node-gyp文档以获取在Windows上的安装要求。 - dNitro
5个回答

9

我建议您使用bcrypt-nodejs:

https://www.npmjs.com/package/bcrypt-nodejs

它提供了几乎相同的功能并易于使用。

原始回答:

您可以尝试以下操作:

  1. 安装Python(http://www.python.org/download/releases/2.7.5/
  2. 安装Visual Studio 2012/13 Express(或其他版本)
  3. 安装Windows SDK(适用于Windows 7/8)
  4. 安装Win64 OpenSSL v1.0.1g
  5. 以管理员身份打开“VS2012的Developer Command Prompt”,然后测试安装

然后执行以下操作:

  • npm install node-gyp -g
  • npm install bcrypt -g

不行,结果相同。 - devnull69
@devnull69,你能否尝试一下我在最近的编辑中提到的事情? - Pankaj kumar Panigrahi
1
bcrypt-nodejs是胜利者。 - devnull69
请参考@Whymarrh的回答。首先需要运行npm install --global --production windows-build-tools,然后再安装bcrypt - Conor Patrick

7

我遇到了同样或类似的错误。 在尝试安装bcrypt之前运行以下命令可以解决问题:

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

6
今天我在尝试在Windows 10桌面上安装bcrypt时遇到了同样的问题。原来bcrypt支持Node的稳定版本,可以查看文档以获取更多信息。
对我来说解决方案是:
  1. 将Node升级到稳定版本:我手动从Node网站下载并安装了Windows安装程序。
  2. 全局安装Windows构建工具:npm install --global --production windows-build-tools
  3. 最后执行npm install bcrypt --save
完成以上步骤后一切正常。

Node.js现在包含了Windows的构建工具。你可能不再需要这个工具了。详情请见https://github.com/felixrieseberg/windows-build-tools。https://www.npmjs.com/package/windows-build-tools - Artyom Ionash

0

我也遇到了这个错误。

我使用以下命令重新安装了node-gyp npm install node-gyp -g 然后我重新安装了bcrypt npm install bcrypt 最终成功了


0
在开发 Node API 项目时,
解决方案:

rm -rf node_modules/bcrypt

npm install node-gyp -g

npm install bcrypt@[版本号] -g

在 Windows 10 上对我有效。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接