Why I am not able to render my ReactJS application using PhantomJS 2.1.1?

后端 未结 2 1147
刺人心
刺人心 2020-11-30 14:11

In order to test my react app using webdriver.io, I need to launch it using phantomjs.

At first I thought the problem was webdriver.io but I\'ve realized that Phanto

2条回答
  •  借酒劲吻你
    2020-11-30 14:38

    Probably has to do with the lack of ES6 support in PhantomJS. To check I added page.onError() callback to your script (always handy!) and opened some React example site to get this error:

    ReferenceError: Can't find variable: Symbol

    To polyfill Symbol one can inject a core.js script from this excellent package into the page before loading the target url:

    page.onInitialized = function() {
        if(page.injectJs('core.js')){
            console.log("Polyfills loaded");
        }    
    }
    

    But that's for opening external sites. If the site that's being tested is under your development (as localhost url suggests) you probably could do with just configuring babel as is shown in this answer.

提交回复
热议问题