首页 文章

在Windows 7上为phantomjs安装“弱”模块时,node-gyp重建失败

提问于
浏览
2

我正在尝试在Windows 7(64位)计算机上安装phantomjs-node模块 . 安装“弱”模块时似乎存在node-gyp重建错误 .

我跟着node-gyp windows installation steps并确保我安装了python并正确设置了它的路径 .

我还有visual-gyp所需的visual c和其他要求 . 遗憾的是,我无法修复node-gyp重建错误 .

我安装了以下内容

  • node - 0.8.14(64位)

  • python - 2.7.3(64位)

  • Microsoft Visual C 2010(64位,也安装了32位以防万一,因为64位没有帮助)

  • Visual Studio 2010(专业版)和Visual Studio 2012(快递,包括Web和桌面)

  • Windows SDK 7.1

我在安装 weak 模块时遇到的错误是:

C:\ Program Files(x86)\ MSBuild \ Microsoft.Cpp \ v4.0 \ Microsoft.Cpp.InvalidPlatform.Targets(23,7):错误MSB8007:项目'weakref.vcxproj'的平台无效 . 平台=“64” . 您可能会看到此消息,因为您正在尝试构建没有解决方案文件的项目,并且已指定了此项目不存在的非默认平台 .

我遇到了上述问题,尝试了所有链接并正确安装了所有node-gyp要求 . 非常感谢 .

4 回答

  • 5

    我一直在寻找这个答案,上面的修复对我来说不起作用 .

    我发现像魅力一样的解决方案就在这里:Cannot install node modules that require compilation on Windows 7 x64/VS2012

    npm install phantom -msvs_version=2012
    
  • 1

    这些解决方案都没有奏效,或者有太多未知因素,所以我需要一个更简单的解决方案 . 我所做的是使用https://github.com/sgentle/phantomjs-node页面上建议的方法

    dnodeOpts property could help you to control dnode settings, so you could disable weak by setting it false to avoid that complicated installations.
    
    var phantom = require('phantom');
    
    phantom.create(function (ph) {
      ph.createPage(function (page) {
        /* the page actions */
      });
    }, {
      dnodeOpts: {
        weak: false
      }
    });
    

    因此,假设您使用的是Windows(否则您根本不会遇到此问题),只需将dnodeOpts设置为false,如上所示,然后结束phantom.create函数 . 例如,如果您使用的是入门代码:

    phantom.create(function (ph) {
        ph.createPage(function (page) {
            page.open("http://www.google.com", function (status) {
              console.log("opened google? ", status);
              page.evaluate(function () { return document.title; }, function (result) {
                console.log('Page title is ' + result);
                ph.exit();
              });
            });
        });
    }, {
        dnodeOpts: {
            weak: false
        }        
    });
    
  • 2

    尝试重新安装Windows SDK,它应该解决问题 .

  • 3

    经过多次试验,我能够解决问题 .

    我重新安装了Windows sdk 7.1,这次我更改了安装sdk的默认路径 . 早些时候,sdk默认安装到

    C:\Program Files\Microsoft SDKs\Windows\v7.1

    但是当我查看C:\ Program Files \ Microsoft SDKs安装完成后,我找不到任何Windows sdk,因为它已安装在C:\ Program Files(x86)\ Microsoft SDKs \ Windows文件夹中 . 因此,在重新安装Windows sdk时,我已将指向C:\ Program Files \ Microsoft SDKs的默认路径更改为C:\ Program Files(x86)\ Microsoft SDKs,这有所帮助 .

    Before re-installing windows sdk make sure to uninstall all the visual c++ versions that got installed.

    弱模块已安装但有警告,但这并没有引起任何问题 . 希望这可以帮助 .

相关问题