I have a static site build with NextJS hosted on Google Cloud Storage, and I’m running into an issue with page refreshes. When I navigate from https://example.com/auth to https://example.com/dashboard?platform=ABC, everything works as expected. But if I refresh the page at https://example.com/dashboard?platform=ABC, I get an error:
<Error> <Code>NoSuchKey</Code> <Message>The specified key does not exist.</Message> </Error>
It seems like Google Cloud Storage is looking for an exact file match with the query string, but can’t find it. Is there a way to prevent this error on page refreshes or handle query parameters correctly?
Hi @kamal_lp
Welcome to Google Cloud Community!
The issue you're facing with your NextJS static site on Google Cloud Storage (GCS) is related to how Next.js handles routing and query parameters. Next.js pre-renders static pages, and GCS stores them with exact file paths. When you refresh a page with a query string like (https://example.com/dashboard?platform=ABC), the browser requests the specific file with the query string encoded in the path (dashboard?platform=ABC.html). Since Next.js doesn't pre-render pages with query strings, this file won't exist on GCS, leading to the "NoSuchKey" error. You may try the following workarounds:
If the above option doesn't work, you can contact Google Cloud Support to further look into your case. Let me know if it helped, thanks!