2016-12-08 35 views
0

我想用phantomjs節點來捕獲屏幕。在我的組件我進口const phantom = require('phantom');。然後,點擊之後我想運行方法 -reactjs - phantomjs-node問題與「FS」模塊

printOnePage(){ 
     phantom.create().then(function(ph) { 
      ph.createPage().then(function(page) { 
       page.open('https://stackoverflow.com/').then(function(status) { 
        console.log(status); 
        page.property('content').then(function(content) { 
         console.log(content); 
         page.close(); 
         ph.exit(); 
        }); 
       }); 
      }); 
     }); 
} 

但我仍然gettint錯誤 -

webpack:///./~/phantomjs-prebuilt/lib/phantomjs.js?:8 Uncaught Error: Cannot find module "fs"(…) 

任何提示,怎麼辦?

回答

1

看起來像一個webpack配置錯誤。上的錯誤的issue表明,一個塊

node: { 
    fs: "empty" 
} 

需要被添加到的WebPack配置。另一種補救措施,it seems,可能會添加一個選項

target: 'node', 

到webpack配置。