编译 bcrypt 时出错 - node.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14573488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:02:38  来源:igfitidea点击:

Error compiling bcrypt - node.js

node.jsnpmbcrypt

提问by Tim Daubenschütz

I'm trying to install bycrpt via npm installusing Windows 7 Ultimate x64. This is my install log:

我正在尝试通过npm install使用 Windows 7 Ultimate x64安装 bycrpt 。这是我的安装日志:

D:\Dropbox\Projekte\RZ\Finance-Man-GUI\node_modules\bcrypt>node "C:\Program File
s\nodejs\node_modules\npm\bin\node-gyp-bin\..\..\node_modules\node-gyp\bin\node
-gyp.js" rebuild
npm http GET https://registry.npmjs.org/mime/1.2.6
npm http 304 https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/cssom
npm http 304 https://registry.npmjs.org/hooks/0.2.1
npm http 304 https://registry.npmjs.org/mongodb/1.2.8
npm http 304 https://registry.npmjs.org/ms/0.1.0
npm http 304 https://registry.npmjs.org/sliced/0.0.3
npm http 304 https://registry.npmjs.org/muri/0.1.0
npm http 304 https://registry.npmjs.org/mime/1.2.6
npm http GET https://registry.npmjs.org/crc/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http GET https://registry.npmjs.org/bytes/0.1.0
npm http GET https://registry.npmjs.org/formidable/1.0.11
npm http GET https://registry.npmjs.org/qs/0.5.1
npm http GET https://registry.npmjs.org/bson/0.1.5
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(29
7,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.
  TargetFrameworkVersion or PlatformToolset may be set to an invalid version nu
mber. [D:\Dropbox\Projekte\RZ\Finance-Man-GUI\node_modules\bcrypt\build\bcrypt_
lib.vcxproj]
  blowfish.cc
  bcrypt.cc
  bcrypt_node.cc
..\src\bcrypt.cc(232): warning C4267: '=' : conversion from 'size_t' to 'unsign
ed char', possible loss of data [D:\Dropbox\Projekte\RZ\Finance-Man-GUI\node_mo
dules\bcrypt\build\bcrypt_lib.vcxproj]
c:\users\timd\.node-gyp
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;E:\Program Files\Java\jdk1.6.0_38\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\ruby-1.9.2\bin;C:\Program Files (x86)\git\bin;C:\Program Files (x86)\git\cmd;E:\Program Files (x86)\Heroku\bin;C:\mongodb-win32-x86_64-2.2.2\bin;E:\xampp\mysql\bin;E:\xampp\apache\bin;E:\Python27;C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcpackages;C:\Program Files\Microsoft Windows Performance Toolkit\;E:\Program Files (x86)\openssl-0.9.8k_X64\bin
.8.18\deps\uv\include\ares.h(49): fatal error C1083: C annot open include file: 'winsock2.h': No such file or directory [D:\Dropbox\Pr ojekte\RZ\Finance-Man-GUI\node_modules\bcrypt\build\bcrypt_lib.vcxproj] gyp ERR! build error gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.e xe` failed with exit code: 1 gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\ npm\node_modules\node-gyp\lib\build.js:255:23) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:99:17) gyp ERR! stack at Process._handle.onexit (child_process.js:678:10) gyp ERR! System Windows_NT 6.1.7600 gyp ERR! command "node" "C:\Program Files\nodejs\node_modules\npm\node_modu les\node-gyp\bin\node-gyp.js" "rebuild" gyp ERR! cwd D:\Dropbox\Projekte\RZ\Finance-Man-GUI\node_modules\bcrypt gyp ERR! node -v v0.8.18 gyp ERR! node-gyp -v v0.8.2 gyp ERR! not ok npm ERR! [email protected] install: `node-gyp rebuild` npm ERR! `cmd "/c" "node-gyp rebuild"` failed with 1 npm ERR! npm ERR! Failed at the [email protected] install script. npm ERR! 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-gyp rebuild npm ERR! You can get their info via: npm ERR! npm owner ls bcrypt npm ERR! There is likely additional logging output above. npm ERR! System Windows_NT 6.1.7600 npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nod ejs\node_modules\npm\bin\npm-cli.js" "install" npm ERR! cwd D:\Dropbox\Projekte\RZ\Finance-Man-GUI npm ERR! node -v v0.8.18 npm ERR! npm -v 1.2.2 npm ERR! code ELIFECYCLE npm http 304 https://registry.npmjs.org/crc/0.2.0 npm http 304 https://registry.npmjs.org/qs/0.5.1 npm http 304 https://registry.npmjs.org/pause/0.0.1 npm http 304 https://registry.npmjs.org/bson/0.1.5 npm http 304 https://registry.npmjs.org/formidable/1.0.11 npm http 304 https://registry.npmjs.org/bytes/0.1.0 > [email protected] install D:\Dropbox\Projekte\RZ\Finance-Man-GUI\node_modules\mongoos e\node_modules\mongodb\node_modules\bson > node install.js || (exit 0) ================================================================================ = = = Attempting to build bson c++ extension = = Windows: no build will be attempted as binaries are prepackaged = = Unix: on failure the package will still install without the C++ extension = = = ================================================================================ npm ERR! npm ERR! Additional logging details can be found in: npm ERR! D:\Dropbox\Projekte\RZ\Finance-Man-GUI\npm-debug.log npm ERR! not ok code 0

I've already installed Python < v2.7 and .NET Framework SDK 2.0. I also downloaded a package called win7sdkx64.exe which was what i think the sdk for Visual Studio. I liked all of the dependencies in my Pathas following:

我已经安装了 Python < v2.7 和 .NET Framework SDK 2.0。我还下载了一个名为 win7sdkx64.exe 的包,我认为它是 Visual Studio 的 sdk。我喜欢我的所有依赖项,Path如下所示:

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

but i still get these errors. What can i try next? Install Visual Studio completly?

但我仍然收到这些错误。接下来我可以尝试什么?完全安装 Visual Studio?

回答by Noah

Ditch the bcrypt module and use a native JavaScript library instead. bcrypt-nodejsrequires no compilation and provides almost the same functionality as the compiled bcrypt.

放弃 bcrypt 模块并改用原生 JavaScript 库。bcrypt-nodejs不需要编译,并提供与编译后的 bcrypt 几乎相同的功能。

回答by diproart

This is correct way to install bcryptover npm on Windows 7/8 x64

这是在Windows 7/8 x64上通过 npm安装bcrypt 的正确方法

Pre:

前:

Post:

邮政:

Open "Developer Command Prompt for VS2012"as Administrator and test install:

以管理员身份打开“VS2012 开发人员命令提示符”并测试安装:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools

p.s. My current Windows environment: win8 x64, node 0.10.x. All works nice.

ps 我当前的 Windows 环境:win8 x64,节点 0.10.x。一切都很好。

UPDATE (2016): Note for Windows 10 x64

更新(2016 年):Windows 10 x64 的注意事项

Visual Studio Express Desktop Editionsolves node-gyp problem. Just install it and it will work for node-gyp.

Visual Studio Express桌面版解决了 node-gyp 问题。只需安装它,它就可以用于 node-gyp。

Links:

链接:

回答by Drasius

How I resolved this.

我是如何解决这个问题的。

My enviroment: Windows 8.1 x64, Node v0.12.2, npm v2.7.5

我的环境:Windows 8.1 x64、Node v0.12.2、npm v2.7.5

Install all components:

安装所有组件:

  1. Install latest 2.x Python, download Python(I downloaded 2.7.9)
  2. Install Visual Studio 2012/13 Express (or other)
  3. Install Windows SDK (for Windows 7 / 8)
  4. Install Win64 OpenSSL v1.0.1g, download it from here(I loaded "Win64 OpenSSL v1.0.2a" latest)
  1. 安装最新的2.x Python, 下载Python(我下载的是2.7.9)
  2. 安装 Visual Studio 2012/13 Express(或其他)
  3. 安装 Windows SDK(适用于 Windows 7 / 8)
  4. 安装Win64 OpenSSL v1.0.1g,从这里下载 (我最新装的是“Win64 OpenSSL v1.0.2a”)

After all components is installed [Important]:

安装完所有组件后【重要】:

Open "Developer Command Prompt for VS2012" as Administrator

以管理员身份打开“VS2012的开发人员命令提示符”

[for VS 2012] Go to

[对于 VS 2012] 转到

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools

[for VS 2013] Go to

[对于 VS 2013] 转到

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

Execute command "VsDevCmd.bat"

执行命令“VsDevCmd.bat”

Then you can execute these cmd:

然后你可以执行这些cmd:

npm install --g --production windows-build-tools
npm install bcrypt

And for me it worked (I have trouble to launch, because from beginning I no execute command "VsDevCmd.bat").

对我来说它有效(我无法启动,因为从一开始我就没有执行命令“VsDevCmd.bat”)。

Note:

笔记:

  1. If it still not executes try to Execute command in simple Command prompt opened as Administrator
  2. Or if bcrypt is installing successfully and executing npm install in your project it fails. Check bcrypt version in package.json. In my case there was "bcrypt": "0.7.x" dependency was specified, and I have newer bcryot version, so after changind it to "bcrypt": "0.8.x", everything installed successfully.
  1. 如果它仍然没有执行,请尝试在以管理员身份打开的简单命令提示符中执行命令
  2. 或者,如果 bcrypt 安装成功并在您的项目中执行 npm install 它将失败。检查 package.json 中的 bcrypt 版本。在我的情况下,指定了“bcrypt”:“0.7.x”依赖项,并且我有更新的bcryot版本,因此将其更改为“bcrypt”:“0.8.x”后,一切都安装成功。

回答by Ricky Boyce

For anyone still facing errors installing bcrypt in 2017.

对于在 2017 年仍然面临安装 bcrypt 错误的任何人。

An npm module has been released to handle Window's native dependency issues by Felix Rieseberg and other contributors. .NET Framework 4.5.1 is the only requirement for Windows 7 / Vista.

Felix Rieseberg 和其他贡献者已经发布了一个 npm 模块来处理 Window 的本机依赖问题。.NET Framework 4.5.1 是 Windows 7 / Vista 的唯一要求。

With admin privileges, run:

使用管理员权限,运行:

##代码##

回答by Nick Campbell

Looking at the error I see

看着我看到的错误

c:\users\timd.node-gyp\0.8.18\deps\uv\include\ares.h(49): fatal error C1083: Cannot open include file: 'winsock2.h': No such file or directory

c:\users\timd.node-gyp\0.8.18\deps\uv\include\ares.h(49): 致命错误 C1083: 无法打开包含文件: 'winsock2.h': 没有那个文件或目录

You'll need to fix that before you can move further. Presumably, you've either figured this out or moved on since it's been a month.

您需要先解决这个问题,然后才能进一步移动。大概一个月以来,您要么已经弄清楚了这一点,要么继续前进。

Take a look at winsock2.h, no such file or directory

看看winsock2.h,没有那个文件或目录