petkaantonov/bluebird · critical · Error

No async scheduler available See http://goo.gl/MqrFmX

Error message

No async scheduler available

    See http://goo.gl/MqrFmX

What it means

This error is thrown by Bluebird's internal Async scheduler (src/async.js) when an asynchronous callback needs to be scheduled but no scheduler implementation (setImmediate, MutationObserver, MessageChannel, setTimeout, etc.) could be set up in the current environment. Bluebird needs a macrotask/microtask mechanism to flush its queue; if all detection fails, _schedule is missing and this Error is thrown. It means the runtime environment is not supported or has been sandboxed in a way that removed async scheduling primitives.

Source

Thrown at src/async.js:62

    }
};

// Must be used if fn can throw
Async.prototype.throwLater = function(fn, arg) {
    if (arguments.length === 1) {
        arg = fn;
        fn = function () { throw arg; };
    }
    if (typeof setTimeout !== "undefined") {
        setTimeout(function() {
            fn(arg);
        }, 0);
    } else try {
        this._schedule(function() {
            fn(arg);
        });
    } catch (e) {
        throw new Error(NO_ASYNC_SCHEDULER);
    }
};

//When the fn absolutely needs to be called after
//the queue has been completely flushed
function AsyncInvokeLater(fn, receiver, arg) {
    ASSERT(arguments.length === 3);
    this._lateQueue.push(fn, receiver, arg);
    this._queueTick();
}

function AsyncInvoke(fn, receiver, arg) {
    ASSERT(arguments.length === 3);
    this._normalQueue.push(fn, receiver, arg);
    this._queueTick();
}

function AsyncSettlePromises(promise) {

View on GitHub (pinned to c220cfe480)

Solutions

  1. Verify setTimeout/setImmediate/MutationObserver/MessageChannel exist in the target environment; restore whichever is missing
  2. Run Bluebird in a supported environment (Node.js or a modern browser) instead of a stripped-down sandbox
  3. Check bundler configuration so globals (timers) are not polyfilled away or undefined in the bundle scope
  4. Update Bluebird to a version supporting the runtime, or supply a custom scheduler build
  5. If the error appears in tests, stop deleting/stubbing global timer functions before requiring Bluebird

Example fix

// before (test setup broke schedulers)
global.setTimeout = undefined;
const Promise = require('bluebird');
// after
const Promise = require('bluebird'); // keep timers intact, or restore before require
global.setTimeout = require('timers').setTimeout;
Defensive patterns

Strategy: validation

Validate before calling

function hasAsyncScheduler() {
  return typeof setImmediate === 'function' ||
    typeof setTimeout === 'function' ||
    (typeof MutationObserver === 'function') ||
    (typeof MessageChannel === 'function');
}
if (!hasAsyncScheduler()) throw new Error('Environment lacks async scheduler; Bluebird cannot run here');

Type guard

const schedulerSupported =
  typeof globalThis.setImmediate === 'function' ||
  typeof globalThis.setTimeout === 'function';

Try / catch

try {
  return Promise.resolve(value);
} catch (e) {
  if (String(e.message).includes('No async scheduler')) {
    return fallbackSyncPath(value); // avoid bluebird in this env
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any Bluebird API that queues an async item in an environment where async.invokeLater/_schedule is undefined — typically exotic runtimes (restricted sandboxes, embedded JS engines, mocked test environments where setTimeout/setImmediate/MutationObserver/MessageChannel are all deleted) or a broken browser bundle where Bluebird failed to detect a scheduler.

Common situations: Running Bluebird inside Web Workers with unusual build configs, in restricted VM sandboxes (e.g. custom eval environments), in old browsers lacking every scheduler API, or in unit-test environments that stub out global timers and break Bluebird's scheduler detection.

Related errors


AI-assisted analysis of petkaantonov/bluebird@c220cfe480 (2026-09-02). Data as JSON: /api/errors/0871af85ba460ead. Report an issue: GitHub.