2015-10-05 102 views
0

我想在MEAN棧中生成報告,但在我的Ubuntu OS服務器上安裝幻像二進制文件並使用幻影node_module + rasterize.js拋出錯誤以下。PhantomJS拋出錯誤(rasterize.js)

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 

這是我的測試代碼。

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

您是否使用stream,net,http模塊運行'npm install'? –

+0

我已經在server.js文件中使用了http模塊 – Robus

回答

1

嘗試運行命令: npm install -g events stream net http

不過,我認爲你做了錯誤的方式建立一個節點項目。例如,如果你想創建一個項目需要PhantomJS。您應該按照以下步驟操作:

# create project directory 
mkdir myproject 
cd myproject 

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

# create your project file 
+0

最終〜這就解決了這個問題。 從終端使用NPM安裝幻象--save , 節點[文件名] 它看起來該phantomjs二進制文件具有到節點及其模塊以運行文件的訪問權限。 – Robus