npm install -g 量角器错误

error on npm install -g protractor

当我安装量角器时出现此错误:

C:\Users\andreir\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modules\utf-8-validate>node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.Cpp.InvalidPlatform.Targets(23,7): error MSB8007: The Platform for project 'validation.vcxproj' is invalid. Platform='x64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Platform that doesn't exist for this project. [C:\Users\andreir\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modules\utf-8-validate\build\validation.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` 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:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\andreir\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modules\utf-8-validate
gyp ERR! node -v v0.10.38
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

我不明白错误在哪里...

我有(相关): Windows 8.1 专业版 x64, Python 2.7.10, VS 2012 专业版

这个问题,正如错误所说,是由于 selenium-webdriver

需要 WebSocket 需要的 utf-8-validate 模块的编译
node_modules\protractor\node_modules\selenium-webdriver\node_modules\ws\node_modules\utf-8-validate

编译器找不到 x64 的项目配置

The Platform for project 'validation.vcxproj' is invalid. Platform='x64'

在此 Github Issue 中,解决方案是重新安装 VisualStudio 和 Windows SDK。

无论如何,这是一个可选的依赖项,所以你可以不用它,当你弄明白的时候,运行

npm install --no-optional