All posts

How to Fix Promise Allsettled Error in Node.js

Learn how to diagnose and fix the promise allsettled error in Node.js. Includes code examples and prevention tips.

Stumbled on a promise allsettled error in your Node.js application? This common issue has a well-known fix that you can apply in minutes.

The Problem

Promise.allSettled() was introduced in ES2020. If your Node.js application targets older Node.js versions (below 12.9) or uses a bundler configuration that doesn't include the necessary polyfills, you'll encounter a TypeError: Promise.allSettled is not a function at runtime.

How to Fix It

The best approach is to upgrade your Node.js version. If that's not possible, add a polyfill:

// Option 1: Polyfill for older environments
if (!Promise.allSettled) {
  Promise.allSettled = (promises) =>
    Promise.all(
      promises.map((p) =>
        Promise.resolve(p)
          .then((value) => ({ status: "fulfilled", value }))
          .catch((reason) => ({ status: "rejected", reason }))
      )
    );
}

// Option 2: Use it with proper error handling
const results = await Promise.allSettled([
  fetchUsers(),
  fetchOrders(),
  fetchProducts(),
]);

const fulfilled = results.filter((r) => r.status === "fulfilled");
const rejected = results.filter((r) => r.status === "rejected");

if (rejected.length > 0) {
  console.warn("Some requests failed:", rejected.map(r => r.reason));
}

// Process successful results
const data = fulfilled.map((r) => r.value);

When to Use allSettled vs all

  • Promise.all fails fast on the first rejection — use when all promises must succeed
  • Promise.allSettled waits for everything and reports each result individually — use when you want partial results even if some promises fail

Node.js Version Check

Run node --version to verify your runtime. Version 12.9.0+ supports allSettled natively. For production, targeting Node 16+ or 18+ is recommended.

Track unhandled promise rejections and allSettled failures automatically with Bugsly — get full stack traces for every rejected promise in your Node.js app.

Try Bugsly Free

Track up to 100 issues per month on the free plan, with unlimited events and no credit card required.

Get Started Free