next.js: buildManifest 404 causing app failure

Bug report

Describe the bug

A clear and concise description of what the bug is.

I have a Next.js application which uses getStaticProps and getStaticPaths. It is running inside a docker container with the server target, and I am repeatedly running into a 404 error when trying to fetch the buildManifest.js file, which causes all navigation to break. It also causes direct navigation to pages that don’t have a cached version yet to hang forever on the fallback page.

To Reproduce

You can see a hanging fallback page here: https://beta.openebooks.us/app/collection/https%3A%2F%2Fqa-circulation.openebooks.us%2FUSOEI%2Fgroups%2F406

You can see the app working, but navigation not working here (because this path was cached before the problem started): https://beta.openebooks.us/app

If the buildManifest file is cached in the browser, for example by visiting the working page and then directly navigating to the not-working page, the not-working page will render correctly, though you will now see 404s on other files, like app.json, etc in the console.

The code producing this behavior is here https://github.com/NYPL-Simplified/circulation-patron-web

Expected behavior

The buildManifest should not 404, and SSG should not hang.

Screenshots

The buildManifest 404: image

The app.json 404: image

Other file 404: image

System information

This is running in a docker image built on top of node:12.2.0-alpine with Next.js version ^9.5.3.

Additional Context

This doesn’t seem to be always happening. The deployment worked totally fine for some time before this began.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 24 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Yes, I have like 2/3 instances behind a load balancer.

I am now using the last commit hash as build id and it seems to have solved the issue 🤞 I have deployed a couple of times already and haven’t seen it happening again - it wasn’t easy to reproduce so I’ll wait for some more deploys before celebrating.

Here’s how my next.config.js now looks like btw:

const execSync = require("child_process").execSync;

const lastCommitCommand = "git rev-parse HEAD";

module.exports = {
  async generateBuildId() {
    return execSync(lastCommitCommand).toString().trim();
  },
};

Hi! I am having the same (similar) issue.

Not always, but often (specially straight after deploying) the app would load but buildManifest would 404 and the navigation would be completely broken. After refreshing a couple (or sometimes several) times, the file would be found and everything would work as expected.

I am trying configuring the build id as suggested and will soon know if it solves the issue 🤞 - @kristojorg did that work for you?

In the meanwhile I am thinking, shouldn’t such error be kind of louder or somehow handled? Is there a good way to find out whether files don’t load correctly at render time maybe? 🤔

Btw I have seen there’s been talks about navigation not working in the past and I am now guessing some of those might be related to this. Eg this old issue maybe 🤔

I’d like to know as well. Experiencing the same issue with the latest version on production.

@Timer 👋 happened to see this issue which caused app failure between deployments, can I get a sense why it did not make to a formal release, but the change is always with the canary releases? Thanks!

@steedems are you running multiple versions of the app behind some kind of load balancer or system like that? That is (I think) the only thing that should cause my issue. I haven’t tested the fix yet, but instead got rid of all but one instance.

Will let you know once I have an opportunity to try it with the deterministic buildId and multiple instances

@Timer I did find this documentation on the build-id, which I had not previously seen and am planning to try later today: https://nextjs.org/docs/api-reference/next.config.js/configuring-the-build-id

I will let you know if that solves it

And thanks for your quick reply here!

Update: this is not a Next.js issue, but was caused by the load balancer improperly routing traffic to an instance that does not have the necessary file