reactjs - phantomjs-node issues with “fs” module

拥有回忆 提交于 2019-12-25 09:34:41

问题


I am trying to use phantomjs-node to capture screen. In my component i import const phantom = require('phantom');. Then after click i want to run method -

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

But i am still gettint error -

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

Any tips what to do ?


回答1:


Looks like a webpack misconfiguration. An issue on the error suggests that a block

node: {
  fs: "empty"
}

needs to be added to the webpack config. Another remedy, it seems, could be to add an option

target: 'node',

to the webpack config.



来源:https://stackoverflow.com/questions/41032928/reactjs-phantomjs-node-issues-with-fs-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!