question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bluebird promise library not found

See original GitHub issue

I’m attempting to use the built-in promise library, however it can’t seem to be found when running a function being evaluated in the browser. Here’s a simplified case:

const debug = require('debug')('test');
const config = { 'injectBluebird': true, 'bluebirdDebug': true, };
const Horseman = require('node-horseman');
const horseman = new Horseman(config);

horseman
  .on('consoleMessage', function (msg) {
    debug(msg);
  })
  .userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.4.10 (KHTML, like Gecko) Version/8.0.4 Safari/600.4.10')
  .open('https://google.com')
  .evaluate(function () {
    console.log(typeof Promise);
    console.log(typeof P);
    console.log(typeof Bluebird);
  })
  .close();

The output is:

  horseman using PhantomJS from $PATH +0ms
  horseman .setup() creating phantom instance on 12406 +6ms
  horseman phantom created +524ms
  horseman phantom version 2.0.0 +19ms
  horseman page created +10ms
  horseman phantomjs onLoadFinished triggered +10ms success NaN
  horseman injected jQuery +31ms
  horseman injected bluebird +8ms
  horseman:verbose onError +5ms ReferenceError: Can't find variable: Promise
    phantomjs://webpage.evaluate(): 4 in configBluebird
    phantomjs://webpage.evaluate(): 9 in <anonymous> 12406
  horseman .on() consoleMessage set. +7ms
  horseman .userAgent() set +22ms Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.4.10 (KHTML, like Gecko) Version/8.0.4 Safari/600.4.10
  horseman .open() +1ms https://google.com
  horseman phantomjs onLoadFinished triggered +767ms success 1
  horseman injected jQuery +16ms
  horseman injected bluebird +11ms
  horseman:verbose onError +4ms ReferenceError: Can't find variable: Promise
    phantomjs://webpage.evaluate(): 4 in configBluebird
    phantomjs://webpage.evaluate(): 9 in <anonymous> 12406
  horseman .evaluate() +4ms <anonymous>
  test undefined +10ms
  test undefined +0ms
  horseman:verbose .evaluate() finished synchronously +1ms <anonymous> s 12406
  horseman .close(). +5ms

From Horseman documentation, it seems I should access Bluebird via Bluebird.

Lastly, if fn returns a Promise or thenable, it will be waited on and the action in Node will resolve/reject accordingly.

horseman
  .open('http://en.wikipedia.org/wiki/Headless_Horseman')
  .evaluate(function() {
    // Silly example for illustrative purposes.
    return Bluebird.delay(100).return('Hello World');
  })
  .then(function(mesg){
    // Will log 'Hello World' after a roughly 100 ms delay.
    console.log(mesg);
  })
  .close();

From Bluebird documentation, it seems I should access Bluebird via Promise or P.

When using script tags the global variables Promise and P (alias for Promise) become available.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12

github_iconTop GitHub Comments

4reactions
awlaytoncommented, Apr 12, 2016

Awesome. I’ll publish a new version with the fix when I get a chance today.

0reactions
winghouchancommented, Apr 12, 2016

It’s fixed 👍 😄

Thank you so much @awlayton.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installation - Bluebird.js
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >
Error Explanations - Bluebird JS
A promise is a process, it starts and it ends. Promises do not aim to solve such live updating problems directly. One option...
Read more >
Bluebird.js
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >
.error | bluebird
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >
.done | bluebird
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found