Error after deploy: Cannot find module '/var/task/.next/server/middleware-manifest.json'

Netlify URL: https://naughty-varahamihira-fcffe0.netlify.app/
Github repo: GitHub - GabZanMacaw/napoleontest
Vercel URL (same project, working): https://napoleontest.vercel.app/

Background:
I had just updated privacy policy and cookie policy pages. I accidentally used “a” instead of “link” and put a “script” tag in the “_document.tsx” file, which apparently doesn’t work. Got a normal build error. After fixing those issues, the build error went away, the deploy was successful, but now this error pops up when you try to go to the website:

{
  "errorType": "Error",
  "errorMessage": "Cannot find module '/var/task/.next/server/middleware-manifest.json'\nRequire stack:\n- /var/task/node_modules/next/dist/server/next-server.js\n- /var/task/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js\n- /var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js\n- /var/task/___netlify-odb-handler.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
  "trace": [
    "Error: Cannot find module '/var/task/.next/server/middleware-manifest.json'",
    "Require stack:",
    "- /var/task/node_modules/next/dist/server/next-server.js",
    "- /var/task/.netlify/functions-internal/___netlify-odb-handler/handlerUtils.js",
    "- /var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js",
    "- /var/task/___netlify-odb-handler.js",
    "- /var/runtime/UserFunction.js",
    "- /var/runtime/index.js",
    "    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:746:27)",
    "    at Module.require (internal/modules/cjs/loader.js:974:19)",
    "    at require (internal/modules/cjs/helpers.js:93:18)",
    "    at NextNodeServer.getMiddlewareManifest (/var/task/node_modules/next/dist/server/next-server.js:600:20)",
    "    at new Server (/var/task/node_modules/next/dist/server/base-server.js:128:40)",
    "    at new NextNodeServer (/var/task/node_modules/next/dist/server/next-server.js:74:9)",
    "    at getBridge (/var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js:46:28)",
    "    at handler (/var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js:75:46)",
    "    at Runtime.handler (/var/task/node_modules/@netlify/functions/dist/lib/builder.js:41:25)"
  ]
}

I have no idea what that means, and it seems to be specific to Netlify since the exact same project works on Vercel. We can’t use Vercel though.

What I tried:

  • Searching around, no mention of this error.
  • Redeploy with cleared cache, same error.
  • Revert all my changes to last working commit, same error.
  • Creating a new, clean Netlify integration and new repository, same error.

Details:

  • Works on local dev server, and on Vercel.
  • Project needs only one environment variable for the Strapi API URL, which I can’t share… if it’s strictly necessary for you I’ll make a copy.
  • Website uses no serverless functions.

Does anyone know what is going on??

hi there, how weird! i will try and see if i can get someone with more next experience to take a look.

which next version are you using, i wonder?

also you mentioned that you can’t use vercel - i’m curious whether that’s due to a platform limitation or some other reason? thanks!

1 Like

Hi, thanks for the response! Yeah, it is super weird.
I’m using next 11.0.0 and react 17.0.2.

As on why we can’t use Vercel, our client already has a different project by another company hosted on Vercel with the same domain. You can’t have two different accounts with the same domain, and they won’t give us access to their Vercel account, so the solution we found is to host it on Netlify instead.

gotcha, makes sense! thanks for the info. I’ve asked some next knowledgeable folks to review, hopefully we will have some answers for you soon!

1 Like

Hey @GabZanMacaw,

We discussed this with our engineers yesterday and have filed a bug for them to investigate it further:

You can follow along the discussion there and add any more details if you wish to.

1 Like

Hi @hrishikesh thank you for the response! I’ll watch the issue to see if this problem is solved. Meanwhile I’ll find a different solution.

1 Like

Hey! I’m also with this obstacle right now.

Watching the issue!

Same here!

This error just happens in the Netlify build.

It looks to be an issue of incompatibility of next 11.0.0 (or older) with new versions of netlify plugins.
you can read more in this github issue: [Bug]: Updating plugin to v4 causes 502 error on some routes · Issue #1103 · netlify/next-runtime · GitHub

2 Likes

Just updated to Next 12 and yeah, it works now! Although the bug seems to be on Netlify’s side, I’ll still consider my problem solved, since I was able to upgrade and build without any issues. Thank you!

1 Like

Thanks so much for following up, @GabZanMacaw! Glad everything is working for you now.

We have the same exact problem. We can’t build our NextJS website on Netlify. It works perfectly fine on Vercel. On Netlify the error is: Error - Cannot find module ‘/var/task/.next/server/middleware-manifest.json’

Unfortunate. We would like to use Netlify, but can’t get it to build b/c of this errors. We don’t even use middleware.

Hey there, @osseonews :wave:

Sorry to hear you are having difficulties. Can you please share the URL to your site, as well as your most recent deploy log? We will look into this further for you.

So, actually it seems like a requirement to use Next 12 on Netlify when it’s a new build. This was our problem. We upgraded, fixed some of incompatibilities with Next12 (NextImage is slightly different), and were able to build. i think you need to put this in your docs somewhere that Next 12 is required.

Next 11 does work too. Could you confirm which version you were using before?