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.
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.
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!
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.
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.