reactjs - phantomjs-node与" fs"模

时间:2016-12-08 06:13:46

标签: javascript reactjs phantomjs

我正在尝试使用phantomjs-node捕获屏幕。在我的组件中,我导入const phantom = require('phantom');。然后点击后我想运行方法 -

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

但我仍然得到错误 -

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

任何提示怎么办?

1 个答案:

答案 0 :(得分:1)

看起来像webpack配置错误。错误上的issue表示一个块

node: {
  fs: "empty"
}

需要添加到webpack配置中。另一种补救措施it seems可能是添加选项

target: 'node',

到webpack配置。