node.js - 如何在 Windows 7 上加密 "npm install"

标签 node.js windows bcrypt

我已经安装了 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 吗?如果是,你能指出我正确的方向吗?真的没有 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

最佳答案

我建议你使用 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 开发人员命令提示符”并测试安装

然后:

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

关于node.js - 如何在 Windows 7 上加密 "npm install",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41899719/

相关文章:

node.js - Node 容器无法连接到 mongo 容器

bcrypt - 为什么 bcrypt 模块不能安装在 windows 8 上?

c++ - C中的图像处理

python - 将 bcrypt 添加到 package.json 时,如何使用 docker node alpine Image 解决 "Could not find any Python installation to use"?

node.js - Nodejs Bcrypt + Heroku 部署失败

node.js - 将变量传递给 npm 命令字符串(不是 npm 命令运行的脚本)

node.js - 有没有办法可以将用户定义的值传递给 Neo4j 中的 Limit 子句

javascript - Node js sql查询内连接

mysql - Windows环境下如何将MySQL查询结果输出为csv格式?

windows - 在 ConEmu 中,是否可以在一行中获得所有命令提示符?