Search code examples
javascriptreactjsnext.jshttp-status-code-404

NextJs | _ssgManifest.js, _buildManifest.js 404 and different name for file _app _#### on server build and browser


I have deployed a NextJs app on digitalocean droplet with Ubuntu 22.04.

  • "next": "12.2.3",
  • "react": "18.2.0",

I am getting this 404 error for _ssgManifest.js, _buildManifest.js and _next/static/chunks/pages/_app-83b8d0a73a58c453.js files.

enter image description here

I checked the build on server, files are present there, but in broweser they are showing 404. Another thing I noticed that the file _app-83b8d0a73a58c453.js getting fetched on browser but on server build it is with different name i.e. _app-8ba37a8edc5ef34c.js

What I Tried

  • I checked with and without custom dir for build, but it didn't worked
  • I checked with custom buildID too
const execSync = require("child_process").execSync;

const lastCommitCommand = "git rev-parse HEAD";

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

any help would be greatly appreciated


Solution

  • Solution:

    These files were not matching to what is asked in browser request to what is available at build on server. In my case the reason was that, after build i was not restarting the application.

    if you are using pm2 to serve your application named fe, please run:

    pm2 restart fe
    

    Then Hard refresh your website in browser, it will work.

    If you are using other tool, then please follow docs for the same to restart the application. And if the issue is diffrent than this in your case, please share your solution here.

    Thank you.