无法使用 npm 安装 prerender - "Failed to locate: CL.exe"

could not install prerender using npm - "Failed to locate: CL.exe"

我一直在尝试在本地计算机上安装 PreRender.Io 进行测试。我已经安装了 Python 2.7.10。当我输入:

npm install prerender

报错:

C:\PreRender\node_modules\prerender\node_modules\phantom\node_modules\dnode\node
_modules\weak>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\
node_modules\npm\bin\node-gyp-bin\..\..\node_modules\node-gyp\bin\node-gyp.js"
rebuild )  else (node  rebuild )
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
TRACKER : error TRK0005: Failed to locate: "CL.exe". The system cannot find the
 file specified. [C:\PreRender\node_modules\prerender\node_modules\phantom\node
_modules\dnode\node_modules\weak\build\weakref.vcxproj]


gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild.0\bin\msbuild.exe` fail
ed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\
npm\node_modules\node-gyp\lib\build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074
:12)
gyp ERR! System Windows_NT 6.1.7601

我找不到 CL.exe,在 Google 上快速搜索似乎缺少一些 Visual C++ 编译器。但是,我尝试安装 say VC++ 2008 redistributable x86,但仍然是同样的问题。

知道哪里出了问题吗? OS 是 Windows 7 64 位。

我设法解决了这个问题,尽管它很奇怪。老实说,我不确定是哪一个完全解决了它,因为我已经做了很多事情。我在我的机器上安装了 Visual Studio 2015。以下是我所做工作的总结:

  • 已安装 Visual C++ 编译器,来自 VS 2015 安装。默认情况下它是未勾选的。我认为这就是解决问题的方法。

  • 添加了 CL.exe (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin)stdlib.h 的路径(C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include) 位于 PATH 环境变量。

  • 2015 年 Visual StudioDeveloper Command Prompt 执行 npm install prerender 管理员 运行模式

我正在阅读 Angular JS 教程并遇到了这个问题,但他们的文档表明这不是问题:

"We often see an npm WARN message after a series of gyp ERR! messages. Ignore them. A package may try to re-compile itself using node-gyp. If the re-compile fails, the package recovers (typically with a pre-built version) and everything works."

https://angular.io/guide/quickstart

对我来说,问题是在安装新版本的节点后出现的。 npm install 会显示上面的错误。然后我得到了上面的错误,但不是针对包 PreRender.Io,而是针对 gulp-sass,尽管我相信问题具有相同的根源。为了解决这个问题,我安装了我一直在使用的以前版本的节点 (6.9.5),然后我使用 nvm 来管理节点版本,如下所述:https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/

使用 nvm 切换到以前版本的节点意味着我可以安装 npm 而无需安装我最终不会使用的大型 SDK。