ErrorBellFree

Error library / this error

How to fix it

Access to fetch at 'https://api.example.com' from origin 'https://app.example.com' has been blocked by CORS policy

What it means

The browser asked the server whether your page may read its response, and the server did not say yes. The fix is on the server, not in your front-end code.

Common causes

  • The response has no Access-Control-Allow-Origin header, or it lists a different origin.
  • The browser sent a preflight OPTIONS request and the server did not answer it correctly.
  • Credentials are included but the server uses a wildcard origin.
  • A redirect or proxy strips the headers.

How to fix it

1. Allow your origin on the server

Express example:

import cors from 'cors';
app.use(cors({ origin: 'https://app.example.com', credentials: true }));

2. Handle the preflight request

Answer OPTIONS with the same headers and a 204 status, plus Access-Control-Allow-Methods and Access-Control-Allow-Headers for what you send.

3. In development, use a proxy

Let your dev server forward /api to the backend so the browser sees one origin.

// vite.config.ts
server: { proxy: { '/api': 'http://localhost:4000' } }

4. Do not use mode: "no-cors" to fix it

It hides the response from your code instead of fixing the problem.

Catch it the moment it happens

ErrorBell shows a dot on the page when this error occurs and takes you to the failing line, so you do not have to hunt through the console. Add it to Chrome, it is free.

Related errors