Phantomjs: ReferenceError: Can't find variable: Promise

Created on 25 Jul 2014  路  45Comments  路  Source: ariya/phantomjs

I'm using mocha-phantomjs 3.5.0 (phantomjs 1.9.7). My mocha tests pass in Chrome but phantom gives the error above.

:ghost:

Most helpful comment

Can you stop writing +1 so we don't get useless notifications all the time
Github have introduced reactions. use that instead.

screen shot 2016-04-05 at 15 59 06

All 45 comments

Native Promises are an extremely recent addition (I'm not even sure if it's officially standard yet), so this is not surprising whatsoever. Are there native Promises in your code/tests, or is the error coming from mocha-phantomjs?

They're in my code. Any plan to add support in the near future? Or do you know of any other headless browsers that have implemented them? I suppose I'll have to shim them into my test page otherwise.

Also, (and this is a separate issue, but) same question regarding support for Array-like objects in Function.prototype.apply.

+1 :smile:

+1

+1

:+1:

@JamesMGreene some update about this? :)

I ended using a simple workaround; adding this Promise Polyfill at the beginning of the tests, hope be util for you!

Although the current master isn't quite where we hoped it would be, we are planning to release it as v2.0.0 on January 23rd (?) and work out the remaining kinks from there once we can all shift focus to v2.x.

That said: I have not verified that the native Promise API is implemented in master.

PhantomJS 2 doesn't have native Promise API.

+1

Promise is available natively in all modern browsers except IEs (IE12 has it)... it's a must have!

+1

Node has Promises, ECMA6 will have them and notably SilmerJS has them already. The SlimerJS devs had the idea to make webpage.open to return a Promise which is IMHO a great improvement to the API.

Just ran into this. I'll give the polyfill a try.

Shims (polyfills) for promises work well.

Any progress on this?

Using es6-promise polyfill works for me. But the polyfill must be put into the page's js code, not to the phantomjs script.

+1
es6-promise works for me as well as polyfill though (PhantomJS 2.0.0).

+1

+1

We had the same problem and choose to inject Babel into our test suite for now.
Our unit tests runs on node.js with jasmine and are therefor ok with Promise.
But our cucumber tests runs into phantom.js and we injected Babel libray to polyfill Promise.

https://babeljs.io/ works great, but maybe to have 芦native support禄 of ES6 feature would be even better :)

@floverdevel That is what i have been doing. Would agree that it would be cool to have native support. but there is things that not even a precompiler can solve... like if the website i'm navigate to uses arrow function, generators and what not.
That is why i'm considering switching to SlimerJS to use an up to date Gecko browser. Seems to me that phantomjs is falling behind on the webkits release cycle's :-1:

Would love phantomjs if it used Blinks engine and had auto update as well. Having to wait for a third party to update their product and update their dependency is urck.
It's like this with samsung phones. Just buy Google's Nexa phone and you know you will be the first to receive an update. Don't have to wait for samsung to wait for next android version so they can update the consumer's phone 3-8 month later or even at all. Instead they just stop maintaining it and announce a new phone called Samsung Galaxy s203 special gold edition v2.0

@jimmywarting i love the comparison with Samsung and the Android update :P

+1

+1

+1

+1

+1

+1

+1

+1

+1

+1

Can you stop writing +1 so we don't get useless notifications all the time
Github have introduced reactions. use that instead.

screen shot 2016-04-05 at 15 59 06

Running into this issue also. including https://raw.githubusercontent.com/stefanpenner/es6-promise/master/dist/es6-promise.min.js does the job. Would be great to support es6 in pjs though..

I have an open issue on StackOverflow regarding promise support in PhantomJS and CasperJS. We ended up moving to SlimerJS until the support for native promises is added to PhantomJS. The issue is here: http://stackoverflow.com/questions/36603470/casperjs-phantomjs-es6-promise-polyfill for others facing this same issue. No resolution has been posted on how to handle this in the client and I was unable to inject anything into phantom that would handle the support for whatever reason. If someone has a resolution it would be greatly appreciated otherwise I look forward to the native promise support in Phantom when it becomes available. Thank you for the hard work!

Either es6-promise and promise-polyfill do the trick!
Thank you @dbaba, @zzarcon and @kawing-chiu for the suggestions!

Just need to include one of them in karma.conf.js in files option

es6-promise:
files: ['./node_modules/es6-promise/dist/es6-promise.js']

promise-polyfill:
files: ['./node_modules/promise-polyfill/promise.js']

Please track ES6 support in #14506. Thank you!

+1

@dbaba how did you go about adding the Promise polyfill? Are you adding it to original source webpage or injecting it somehow using PhantomJS?

Thanks in advance.

There's a phantomjs polyfill that can downloaded via the npm manager, https://www.npmjs.com/package/phantomjs-polyfill this helps resolve the promise error you will encounter

@Zoheb-hassan the page of https://github.com/ariya/phantomjs/issues/link is 404

+1 :D Get ES6 support faster ffs.

The following in karma.conf.js did not work for me, @filipalacerda
files: ['./node_modules/es6-promise/dist/es6-promise.js']

I had to change it to this to get it to work :)
files: ['./node_modules/es6-promise/dist/es6-promise.auto.js']

Was this page helpful?
0 / 5 - 0 ratings