nodeJS phantom ReferenceError:未定义Promise

时间:2016-04-05 18:18:26

标签: javascript node.js

问题

我安装了幻像并使用节点v0.10.26

我在幻影中收到了一个Promise错误。我没有看到任何需要安装的依赖项。

以下是我正在使用的幻像的示例代码

/myProject/node_modules/phantom/lib/index.js:15   返回新的Promise(function(resolve){              ^ ReferenceError:未定义Promise     at Object.module.exports.create(/Users/jbyrne/git/tin-validator/node_modules/phantom/lib/index.js:15:14)     在对象。 (/Users/jbyrne/git/tin-validator/phantom.js:6:9)     在Module._compile(module.js:456:26)     at Object.Module._extensions..js(module.js:474:10)     在Module.load(module.js:356:32)     在Function.Module._load(module.js:312:12)     在Function.Module.runMain(module.js:497:10)     在启动时(node.js:119:16)     在node.js:902:3

我将节点升级到v0.11.13,现在得到了 $ node phantom.js 例外:ReferenceError:未定义Map

我安装了幻像并使用节点v0.10.26

我在幻影中收到了一个Promise错误。我没有看到任何需要安装的依赖项。

以下是我正在使用的幻像的示例代码

/myProject/node_modules/phantom/lib/index.js:15   返回新的Promise(function(resolve){              ^ ReferenceError:未定义Promise     at Object.module.exports.create(/Users/jbyrne/git/tin-validator/node_modules/phantom/lib/index.js:15:14)     在对象。 (/Users/jbyrne/git/tin-validator/phantom.js:6:9)     在Module._compile(module.js:456:26)     at Object.Module._extensions..js(module.js:474:10)     在Module.load(module.js:356:32)     在Function.Module._load(module.js:312:12)     在Function.Module.runMain(module.js:497:10)     在启动时(node.js:119:16)     在node.js:902:3

我将节点升级到v0.11.13,现在得到了 $ node phantom.js 例外:ReferenceError:未定义Map

代码

var phantom = require('phantom');

var sitepage = null;
var phInstance = null;

phantom.create()
    .then(function(instance) {
        phInstance = instance;
        return instance.createPage();
    })
    .then(function(page) {
        sitepage = page;
        return page.open('https://stackoverflow.com/');
    })
    .then(function(status) {
        console.log(status);
        return sitepage.property('content');
    })
    .then(function(content) {
        console.log(content);
        sitepage.close();
        phInstance.exit();
    })["catch"](function(e) {
      console.error('Exception: %s', e);
    });

2 个答案:

答案 0 :(得分:0)

您的PhantomJS版本取决于节点0.10中不存在的一些全局对象。您可以将Node升级到最新的稳定版本,或将PhantomJS降级到1.x。

如果您在节点版本之间切换,则可以使用nvm轻松切换。

答案 1 :(得分:0)

将节点升级到0.12 提到的错误是由于幻像中的新Map()行。 在节点0.12

中添加了Map构造函数