Access to XMLHttpRequest at 'https://78831182-pvgk9v0mm-wedothebest4yous-projects.vercel.app/' from origin 'http://localhost:3002' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.Understand this error
(index):21 Q {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
xhr.js:258
GET [https://78831182-pvgk9v0mm-wedothebest4yous-projects.vercel.app/](https://78831182-pvgk9v0mm-wedothebest4yous-projects.vercel.app/) net::ERR_FAILED 401 (Unauthorized)
Hello and welcome, ! We need to know more about your project. If you can share more info about the project and how you're running it, that would help us understand what's happening.
A minimal reproducible example is usually the fastest way to let others see what you see so we can help you debug the problem.
Hi, Thank you for your response. I shall provide the requested information soon.
Access to fetch at 'https://new-express-project-p61e9hmrr-wedothebest4yous-projects.vercel.app/' from origin 'http://localhost:2000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.Understand this error
(index):15
GET https://new-express-project-p61e9hmrr-wedothebest4yous-projects.vercel.app/ net::ERR_FAILED 401 (Unauthorized)
(anonymous) @ (index):15Understand this error
(index):15
Uncaught (in promise) TypeError: Failed to fetch
at (index):15:5
(anonymous) @ (index):15
Promise.then
(anonymous) @ (index):25Understand this error
Vercel Staff
Have you tried adding the headers in your Express configuration instead of a vercel.json file?
Earlier on I had followed the docs over here : https://vercel.com/guides/how-to-enable-cors. The third option is the one which I have been trying since the first and second cases are not mine. Does it mean that this third option will not work, or the way in which I tried is not correct, or it is not currently the recommended way.
Anyways, I have followed the two options you now have suggested, and the feedback enclosed below. The status is the same issue still persists.
Status : The CORS issue reported originally still persists.
Access to fetch at 'https://new-express-project-1efbmmk4s-wedothebest4yous-projects.vercel.app/' from origin 'http://localhost:2000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.Understand this error
(index):15
GET https://new-express-project-1efbmmk4s-wedothebest4yous-projects.vercel.app/ net::ERR_FAILED 401 (Unauthorized)
(anonymous) @ (index):15Understand this error
(index):15
Uncaught (in promise) TypeError: Failed to fetch at (index):15:5
Status : The CORS issue reported originally still persists.
Access to fetch at 'https://new-express-project-lxo25p9y1-wedothebest4yous-projects.vercel.app/' from origin 'http://localhost:2000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.Understand this error
Failed to load resource: net::ERR_FAILEDUnderstand this error
(index):15
Uncaught (in promise) TypeError: Failed to fetch at (index):15:5
Vercel Staff
The third option from that guide could work. But it's best to use the framework's preferred strategy when one is provided since this prevents configuration conflicts. I'd recommend configuring it the "Express" way for your project.
I found some additional tips that could help in your case:
Are you able to check which headers are actually being applied? If the headers are missing, then you know that's the problem. If the headers are present, then something else is causing the error.
It's also worth reading to understand more about CORS. That can help you understand how it works so you can identify what's going wrong.