首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PhantomJS抛出错误(rasterize.js)

PhantomJS抛出错误(rasterize.js)
EN

Stack Overflow用户
提问于 2015-10-05 10:32:14
回答 1查看 549关注 0票数 0

我正在尝试平均堆栈中的幻影以生成报告,但是在我的ubuntu服务器中安装了幻影二进制文件并使用幻影node_module + rasterize.js后,错误抛出。

代码语言:javascript
复制
Error: Cannot find module 'events'

phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:1
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/node_modules/dnode-protocol/index.js:126
Error: Cannot find module 'stream'

phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/lib/dnode.js:2
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/lib/dnode.js:154
Error: Cannot find module 'net'

phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/index.js:3
/home/kb/code/backend/backend/api_server/node_modules/phantom/node_modules/dnode/index.js:138
Error: Cannot find module 'http'

phantomjs://bootstrap.js:289
phantomjs://bootstrap.js:254 in require
/home/kb/code/backend/backend/api_server/node_modules/phantom/phantom.js:8
/home/kb/code/backend/backend/api_server/node_modules/phantom/phantom.js:193
/home/kb/code/backend/backend/api_server/node_modules/phantom/phantom.js:194
TypeError: 'undefined' is not a function (evaluating 'phantom.createWebPage()')

:/modules/webpage.js:905
report.js:7

这是我的测试代码。

代码语言:javascript
复制
var phantom = require('phantom');

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();
      });
    });
  });
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-06 03:11:38

尝试运行命令:npm install -g events stream net http

但是,我认为您设置节点项目的方式是错误的。例如,如果您想要创建一个项目,则需要PhantomJS。您应该执行以下步骤:

代码语言:javascript
复制
# create project directory
mkdir myproject
cd myproject

# install phantomjs for your project
npm install --save phantomjs

# create your project file 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32946421

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档