JavaScript Error

Fix: CORS Policy Error (Access-Control-Allow-Origin)

By Samrat•Last updated: Nov 2026

Exact message

Access to fetch at 'http://...' from origin 'http://...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present.

Quick answer

CORS is a browser security feature. This error means your backend server is not sending the 'Access-Control-Allow-Origin' header, so the browser blocks your frontend from reading the response.

🛠️ Fix it right here with AI Code Explainer

Edit the traceback below if needed, then let our AI suggest a fix without leaving this page.

AI suggestions can be wrong. Review and test before applying.

Why this error happens

Browsers enforce the Same-Origin Policy. If your frontend calls an API on a different domain, the server must explicitly allow it via CORS headers.

Example: Wrong vs Right

Wrong

// Frontend fetch request
fetch('http://localhost:5000/api/data')
  .then(res => res.json());
// Browser blocks it if backend doesn't have CORS headers

Right

// Backend (Express.js example)
const cors = require('cors');
app.use(cors({ origin: 'http://localhost:5173' }));

How to fix it (step by step)

  1. Understand that CORS is a server-side fix, not a frontend fix
  2. If you control the backend, add a CORS middleware
  3. Configure the specific origin for security
  4. For development only, you can use a proxy in Vite/Webpack

Frequently asked questions

Why does it work in Postman but not the browser?

Postman is a backend tool and does not enforce browser security policies like CORS.

What is a preflight request?

For non-simple requests, the browser sends an OPTIONS request first. The server must respond with the allowed methods and headers.

Related Search Terms

cors policy erroraccess-control-allow-origincors error fetchblocked by cors policy

Related JS errors

Need to fix JS code not just errors?

Use the free to paste any JS snippet and get a line-by-line explanation.

Want an AI with memory for your project?

MonsterX AI remembers your codebase across chats.