Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Laravel Echo stops with: Uncaught Options object must provide a cluster

Your error

Uncaught Options object must provide a cluster1 more line it can show

Fix it fast

Most common cause, 1 of 3

VITE_PUSHER_APP_CLUSTER is missing, or the code reads a variable without the VITE_ prefix

Define the cluster from your Pusher app's settings and mirror it into a VITE_ variable, as the Laravel broadcasting guide does, and read that VITE_ name in the Echo config.

Fix
# .env
PUSHER_APP_CLUSTER="mt1"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

// resources/js/echo.js
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: true,
});
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

"Uncaught Options object must provide a cluster" comes from pusher-js 8 when its cluster option is undefined. In Laravel 13 Echo setups, VITE_PUSHER_APP_CLUSTER is missing or newer than the last build, the code reads a name without the VITE_ prefix, or Echo uses broadcaster 'pusher' against Reverb. Set the variable and rebuild, or use broadcaster 'reverb'.

  • Applies to pusher-js 8.6, laravel-echo 2.6, Laravel 13, Vite 8
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Open resources/js/echo.js (or app.js) to see which broadcaster and cluster value Echo gets, then list the VITE_ variables in .env. The pair tells you which cause below applies.

Run this first
grep -n -A8 "new Echo" resources/js/*.js
grep -n "^VITE_PUSHER\|^VITE_REVERB\|^PUSHER_APP_CLUSTER" .env

Then find the line you see in this list and open its fix:

  1. 1VITE_PUSHER_APP_CLUSTER is missing, or the code reads a variable without the VITE_ prefixEcho passes cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER (or PUSHER_APP_CLUSTER) and .env has no VITE_PUSHER_APP_CLUSTER line
  2. 2The variable exists, but the bundle was built before it was added.env is correct, yet the error stays on the deployed site or in a dev server that was started before the change
  3. 3Echo uses broadcaster 'pusher' against Laravel Reverb or another self-hosted serverBROADCAST_CONNECTION=reverb, or a wsHost pointing at your own server, while the Echo config says broadcaster: 'pusher' with no cluster

What does the error look like?

  • Uncaught Options object must provide a cluster
  • Options object must provide a cluster

Cause 1 of 3

VITE_PUSHER_APP_CLUSTER is missing, or the code reads a variable without the VITE_ prefix

You seeEcho passes cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER (or PUSHER_APP_CLUSTER) and .env has no VITE_PUSHER_APP_CLUSTER line

Check

Options object must provide a cluster appears here because the cluster value reached pusher-js as undefined. Vite exposes to browser code only the variables whose names start with VITE_; anything else reads as undefined, and since pusher-js 8.0 a missing cluster throws instead of falling back.

Check
grep -n "PUSHER_APP_CLUSTER" .env resources/js/*.js

Fix

Define the cluster from your Pusher app's settings and mirror it into a VITE_ variable, as the Laravel broadcasting guide does, and read that VITE_ name in the Echo config.

Fix
# .env
PUSHER_APP_CLUSTER="mt1"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

// resources/js/echo.js
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: true,
});

Verify

Restart the dev server and reload: the error is gone and the browser opens a WebSocket to ws-mt1.pusher.com (your cluster name in place of mt1).

Verify
npm run dev

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The variable exists, but the bundle was built before it was added

You see.env is correct, yet the error stays on the deployed site or in a dev server that was started before the change

Check

Options object must provide a cluster after the variable was added means the running bundle still holds the old value. Vite reads .env files when it starts and writes VITE_ values into the JavaScript at build time, so a change does nothing until the dev server restarts or the assets are built again.

Check
ls -lt .env public/build/manifest.json

Fix

If .env is listed above the manifest, it is newer than the build. Restart npm run dev locally. On the server, rebuild the assets as part of the deploy after .env is in place.

Fix
npm run build

Verify

Load the page with the cache disabled; the new asset file name appears in the Network tab and the console stays clean.

Verify
ls -lt public/build/assets/ | head -n 5

Confirmed by vite.dev

Did this fix it?

Cause 3 of 3

Echo uses broadcaster 'pusher' against Laravel Reverb or another self-hosted server

You seeBROADCAST_CONNECTION=reverb, or a wsHost pointing at your own server, while the Echo config says broadcaster: 'pusher' with no cluster

Check

Options object must provide a cluster with a self-hosted WebSocket server means Echo builds a plain Pusher client, which still demands a cluster even though wsHost decides where it connects. Echo's reverb broadcaster supplies an empty cluster for you; the pusher broadcaster does not.

Check
grep -n "BROADCAST_CONNECTION\|REVERB_" .env

Fix

For Reverb, switch the Echo config to the reverb broadcaster with the VITE_REVERB_ variables. For another Pusher-protocol server, keep broadcaster 'pusher' but pass a cluster string together with wsHost; pusher-js uses wsHost when it is set.

Fix
window.Echo = new Echo({
    broadcaster: 'reverb',
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'],
});

Verify

Start Reverb and the dev server; the browser opens its WebSocket to your own host and port.

Verify
php artisan reverb:start
npm run dev

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Keep every value the front end needs as a VITE_ mirror of the server variable in .env.example, so a fresh clone cannot miss one.
  • Build assets in the deploy script after .env is written, never on a developer machine.
  • Pin pusher-js and laravel-echo in package.json and read their changelogs before a major upgrade.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.