opennextjs-netlify: [Bug]: `Error: Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/amp-context'` in NextJS preview mode
Summary
Website is working normally, but when setting NextJS in preview mode to see live Sanity data, Netlify gives a 500 error. Locally, the preview mode works. Also, in a Docker image it works as expected. Netlify is the only place where preview mode fails.
A link to a reproduction repository
Private repository
Expected Result
No error, just NextJS on Netlify in preview mode getting live data from Sanity.
Actual Result
A 500 error in the browser and the error log below.
Steps to reproduce
Don’t know.
Next Runtime version
4.40.3-rc.0
Is your issue related to the app directory?
- Yes, I am using the
appdirectory
More information about your build
- I am building using the CLI
- I am building using file-based configuration (
netlify.toml)
What OS are you using?
None
Your netlify.toml file
`netlify.toml`
[[plugins]]
package = "@netlify/plugin-nextjs"
[[plugins]]
package = "@netlify/plugin-sitemap"
[plugins.inputs]
exclude = [
'.next/404.html',
'.next/404/index.html',
'.next/500.html',
'.next/500/index.html',
]
Your public/_redirects file
None
Your next.config.js file
`next.config.js`
/** @type {import('next').NextConfig} */
module.exports = {
i18n: {
defaultLocale: 'nl',
locales: ['nl'],
},
images: {
domains: ['cdn.sanity.io'],
},
output: 'standalone',
swcMinify: false,
async redirects() {
const sanityRedirects = await fetchSanityRedirects();
return sanityRedirects;
},
};
Builds logs (or link to your logs)
None
Function logs
Function logs
Error: Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/amp-context'
Require stack:
- /var/task/node_modules/next/dist/shared/lib/head.js
- /var/task/node_modules/next/head.js
- /var/task/.next/server/pages/index.js
- /var/task/node_modules/next/dist/server/require.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js
- /var/task/___netlify-handler.js
- /var/runtime/index.mjs
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at /var/task/node_modules/next/dist/server/require-hook.js:54:36
at Module._load (node:internal/modules/cjs/loader:922:27)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at mod.require (/var/task/node_modules/next/dist/server/require-hook.js:62:32)
at require (node:internal/modules/cjs/helpers:121:18)
at Object.<anonymous> (/var/task/node_modules/next/dist/shared/lib/head.js:29:34)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/task/node_modules/next/dist/shared/lib/head.js',
'/var/task/node_modules/next/head.js',
'/var/task/.next/server/pages/index.js',
'/var/task/node_modules/next/dist/server/require.js',
'/var/task/node_modules/next/dist/server/next-server.js',
'/var/task/.netlify/functions-internal/___netlify-handler/___netlify-handler.js',
'/var/task/___netlify-handler.js',
'/var/runtime/index.mjs'
]
}
.next JSON files
None
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 42 (2 by maintainers)
Commits related to this issue
- downgrade to next 13.4.19 as per https://github.com/netlify/next-runtime/issues/2329 — committed to ramicaza/big-agi-query by deleted user 3 years ago
- Downgrade to Next 13.4.19 as per netlify/next-runtime#2329 — committed to bits-and-bytes-association/bitsandbytesassociation.ca by bandrson 3 years ago
- downgrading next to 13.4.19 due to netlify/next-runtime/issues/2329 — committed to ushu3323/precios-riogrande by ushu3323 3 years ago
- fix: fix Vercel deployment with lower version of Next.js Details: https://github.com/netlify/next-runtime/issues/2329 — committed to Frachtwerk/essencium-frontend by qhantom 3 years ago
- fix: fix Vercel deployment with lower version of Next.js (#473) Details: https://github.com/netlify/next-runtime/issues/2329 — committed to Frachtwerk/essencium-frontend by qhantom 3 years ago
Hey everyone.
amp-contextandhead-manager-contextare imported dynamically bynext/head, which means they won’t be properly included in the Netlify function. We can force them to be added by usingnetlify.toml:This solved the issue for me.
Since most messages are from November, I wanted to mention that it’s still an issue. I upgraded to Next 14 and pages with getServerSideProps, broke with the same error.
I see that the issue has been open for 2 months now. I don’t mind Vercel making things hard for other providers, but I would like some confirmation or estimate from Netlify.
I encountered the same issue and was able to work around this for now by downgrading and pinning my application to
"next": "13.4.8".The bug is still present today. Next 14.0.4. Didn’t find a solution.
Hey folks, there’s a related discussion going on in Netlify’s support forum here: https://answers.netlify.com/t/next-js-14-upgrade-results-in-500-status-code/105786/4
In essence, it sounds like they might be working on an overhaul of how Next.js runs on Netlify* and they’d rather focus on that than keep playing whack-a-mole with the current system, as the rate of Next.js updates encountering problems on Netlify is increasing.
*I can’t say that for sure, I don’t work there, but that’s what I inferred from the responses.
I found a solution to my problem, and I want to share it with you in case it can help.
In my situation, downgrading nextjs to the previous version didn’t solve the issue. So, I started to investigate my code. During this process, I was removing third-party code from the _app.js file and discovered that the culprit was the nextjs-progressbar package.
I hope this information is useful to someone.
Same issue when trying to build using
output: "standalone"for any project that uses new@next/third-partiesscript.Get the following error on startup:
Well, I have to remove the fix that temporary solved this bug. I will try that tomorrow if I get the errors back or not.
I was able to go around this problem by adding the following to our next.config.js You might need to specify the file you have in your error message.
I have a similar issue when deployed to Netlify; locally work fine?
I am trying different versions of the next 13 but have had no luck so far.
Some have issue with
amp-contextmodule my one withhead-manager-contextmodulesame error for “next”: “^13.4.6”
I am also seeing a similar deploy only issue on pages that use getServerSideProps and import Head from ‘next/head’ and add metadata. 500 error. Using page routing and NextJS 14.0.2. Downgrading back to 13.4.8 is a work-around for me. For some reason 13.4.19 did not resolve it for me.
I am having a similar error, previewing with Prismic on a NextJS site.
"@netlify/plugin-nextjs": "^4.41.2""next": "^14.0.3",Fixed it by downgrading to
"next": "^13.4.19",Any idea what is going on here? @Skn0tt
I had this issue and the only way I could solve it was to move from netlify to vercel 😦
Same issue here (also fixed for now by going back down to 13.4.9)
Im having the same issue
Also seeing this error on deploy to netlify (next14 with pages routing):
Not able to reproduce locally, the file exists in my node_modules directory. Removing my _document.js file didn’t stop the error from occurring.
Running the build inside a minimal Docker container works well as a workaround, no issues with v14.
We’re having a similar issue and we’re not using preview mode. It appears to happen on pages that use
getServerSidePropsandimport Head from 'next/head';Not working: @netlify/plugin-nextjs@4.41.1 & next@13.5.6 Working: @netlify/plugin-nextjs@4.41.1 & next@13.4.8
We have just upgraded to 13 and still use the /pages router if that makes a difference.