Failed to load response data: No data found for resource with given identifier
Matthew C.
—When using browser dev tools, like Chrome DevTools, to investigate why a fetch request has failed, you may see the following error in the Network tab on the browser dev tools response panel:
Failed to load response data: No data found for resource with given identifier
This can be caused by cross-origin resource sharing (CORS), if your frontend code and the API endpoint are served from different origins and you haven’t set up CORS correctly.
It can also be caused by an incorrect request URL or a connection issue with the server.
If the issue is caused by cross-origin resource sharing (CORS), you’ll see the following error in your browser dev tools Console tab:
Access to fetch at 'http://localhost:1338/api/sync' from origin 'http://localhost:5173' 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.
The CORS header ‘Access-Control-Allow-Origin’ missing error indicates that you need to set up CORS on your server to allow your frontend to access your backend API resources. Add your frontend origin (URL) to the Access-Control-Allow-Origin
header. In an Express app, you can install the CORS npm package and add an origin, as shown in the code below:
import express from "express"; import cors from "cors"; const corsOptions = { origin: "http://localhost:5173" }; const app = express(); app.use(cors(corsOptions));
You can use an API development platform, such as Insomnia or Postman, to test whether the fetch request has a CORS issue. The same-origin policy is a browser security measure that restricts resource fetching from different origins. Insomnia and Postman don’t enforce CORS. To learn more, take a look at this Sentry answer: Why does my JavaScript code receive a “No Access-Control-Allow-Origin header is present on the requested resource” error, while Postman does not?.
If CORS isn’t the issue, make sure that your API route exists.
If the request URL is incorrect, or if there is a server connection issue, you’ll see a “Not Found” error in your browser dev tools Console tab:
POST http://localhost:1338/api/syncc net::ERR_FAILED 404 (Not Found)
You may only see the Failed to load response data: No data found for resource with given identifier
error after multiple page reloads or page navigations if you’re using the Network tab in the dev tools of a Chromium browser and have the preserve log feature enabled. There is a Chromium issue about why some requests that initially show a response later show the error, after further page refreshes or navigation: DevTools: XHR (and other resources) content not available after navigation.
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.