Server.edge not defined Error on nextJS SSR functions cause site to return 500 Errors

I’ve been stuck on 13.4.8 in order to avoid this server.edge issue which we see when we move past that version, but now there’s a security advisory out for anything less than 13.4.20. This raises the urgency of a fix here. @hrishikesh - we’ve been waiting for over 5 months for a fix to this issue. What can be done to escalate this? Does the recently announced v14 resolve this issue?

Regarding the CVE, it doesn’t necessarily apply to sites on Netlify as far as I understand. With that being said, no there’s no update worth sharing with the public about this.

I’m currently facing challenges with my Next.js project, utilizing Approuter, and encountering issues with the @netlify/plugin-nextjs during the prebuilding process. Despite trying various solutions mentioned in this thread, the issue persists. Here’s a summary of my setup:

1.Versions:

  • Next.js: 13.4.9 Approuter
  • @netlify/plugin-nextjs: 4.39.0 or 4.37.4
  • netlify-cli: 17.6.0
  1. Added ‘prebuild’ to package.json.
    this post

When I run the program, the following error occurs:

This function has crashed
An unhandled error in the function code triggered the following message:

Runtime.ImportModuleError - Error: Cannot find module 'next/dist/compiled/react/jsx-dev-runtime' Require stack: - /var/task/node_modules/next/dist/server/require-hook.js - /var/task/node_modules/next/dist/server/next-server.js - /var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js - /var/task/___netlify-odb-handler.js - /var/runtime/index.mjs

Stack trace
Runtime.ImportModuleError: Error: Cannot find module 'next/dist/compiled/react/jsx-dev-runtime'
Require stack:
- /var/task/node_modules/next/dist/server/require-hook.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js
- /var/task/___netlify-odb-handler.js
- /var/runtime/index.mjs
    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)
    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)
    at async start (file:///var/runtime/index.mjs:1282:23)
    at async file:///var/runtime/index.mjs:1288:1
  1. My next.config.js file:
    this post

If anyone has insights into adding the __NEXT_PRIVATE_PREBUNDLED_REACT environment variable using netlify-cli@17.6.0 or any suggestions related to my configurations and versions, your help would be highly appreciated!

[Update]
"I have resolved this issue. The cause was that in the package.json file, the version of Next.js was set as “next”: “13.4.9” instead of “next”: “^13.4.9”.

thanks for sharing your solution with the community!

I’ve been having this issue this week, however unlike everyone else on this thread I’m still using nextjs 12.

I started noticing it happening during deploy previews. The first time it happened, I thought I fired too many API requests in a short time and was rate limited by the server. I’ve waited a few days for it to go away but I see that it hasn’t.

The error happens when trying to access particular API route; https://release--chubic.netlify.app/api/lights, or any invalid url like https://release--chubic.netlify.app/asdfasdf.

Since the logs were only for the production deploy, I make a temporary release to try to capture the errors and prompty rolled back. I’ve pasted the log errors at the bottom.

If you’re able to see my deploy history, this is the last functioning deploy preview.
https://deploy-preview-1144--chubic.netlify.app/

#1145 onwards has had the error.

I tried creating a new deploy starting from the #1144 branch with no changes, and that one has failed as well. It contains no changes except for an additional console.log, which leads me to believe the error might be on netlify’s end rather than mine.
https://deploy-preview-1157--chubic.netlify.app/

Dec 6, 03:24:28 PM: 9557f39a ERROR  TypeError: file.startsWith is not a function
Dec 6, 03:24:28 PM: 9557f39a ERROR      at promises.readFile (/var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js:112:18)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at getSource (node:internal/modules/esm/load:44:20)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at defaultLoad (node:internal/modules/esm/load:130:38)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at new ModuleJob (node:internal/modules/esm/module_job:65:26)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at #createModuleJob (node:internal/modules/esm/loader:290:17)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17)
Dec 6, 03:24:28 PM: 9557f39a ERROR      at async ModuleLoader.import (node:internal/modules/esm/loader:315:23)
Dec 6, 03:24:28 PM: 9557f39a INFO   [GET] /api/lights?type=ceilingLight&vendor=daiko (SSR)
Dec 6, 03:24:31 PM: 9557f39a Duration: 1822.21 ms	Memory Usage: 161 MB	Init Duration: 592.88 ms	
Dec 6, 03:24:37 PM: 7440af7f ERROR  TypeError: file.startsWith is not a function
Dec 6, 03:24:37 PM: 7440af7f ERROR      at promises.readFile (/var/task/.netlify/functions-internal/___netlify-handler/handlerUtils.js:112:18)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at getSource (node:internal/modules/esm/load:44:20)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at defaultLoad (node:internal/modules/esm/load:130:38)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at ModuleLoader.load (node:internal/modules/esm/loader:396:13)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:278:56)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at new ModuleJo
b (node:internal/modules/esm/module_job:65:26)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at #createModuleJob (node:internal/modules/esm/loader:290:17)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:248:34)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:229:17)
Dec 6, 03:24:37 PM: 7440af7f ERROR      at async ModuleLoader.import (node:internal/modules/esm/loader:315:23)
Dec 6, 03:24:37 PM: 7440af7f INFO   [GET] /api/lights?type=ceilingLight&vendor=daiko%2Cpanasonic (SSR)

Your issue has nothing to do with this thread, @senhongo. Please check: All nextjs builds returning 500 error with TypeError: file.startsWith is not a function

Ive tried the step above and im still getting the error below:

This function has crashed

An unhandled error in the function code triggered the following message:

Runtime.ImportModuleError - Error: Cannot find module ‘next/dist/compiled/react/jsx-dev-runtime’ Require stack: - /var/task/node_modules/next/dist/server/require-hook.js - /var/task/node_modules/next/dist/server/next-server.js - /var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js - /var/task/___netlify-odb-handler.js - /var/runtime/index.mjs

Stack traceRuntime.ImportModuleError: Error: Cannot find module ‘next/dist/compiled/react/jsx-dev-runtime’ Require stack: - /var/task/node_modules/next/dist/server/require-hook.js - /var/task/node_modules/next/dist/server/next-server.js - /var/task/.netlify/functions-internal/___netlify-odb-handler/___netlify-odb-handler.js - /var/task/___netlify-odb-handler.js - /var/runtime/index.mjs at _loadUserApp (file:///var/runtime/index.mjs:1087:17) at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21) at async start (file:///var/runtime/index.mjs:1282:23) at async file:///var/runtime/index.mjs:1288:1

Connection details

Netlify internal ID: 01HMQTE6BH9D9NV8XRKJ440A33

This is still broken.

Funny though, the same repo is working fine on Vercel, its just on Netlify I’m getting this error. I want to use it on Netlify however, unable to. Tried updating Next.js version to 13.5.2 however, no luck.

Please update if we have any concrete breakthrough on this.

also having this issue, any updates?

Next Runtime v5 is currently in beta, release candidate dropping sometime in the upcoming weeks which has resolved this issue.

Hey, it seems this will take long. Is there any way I can deploy my site with the beta Runtime v5? I would really want check my website on Netlify as soon as possible, be it on a beata runtime.

will this resolve the full page refresh issue as well?

It’s already available on NPM: @netlify/plugin-nextjs - npm (npmjs.com)

Quite possibly, yes

Thanks, updated to 5.0.0-beta.9. Though an improvement, I’m still getting this error:

Could anyone provide some insights into this issue?

Are you using Next.js 13.5 or above? The Runtime v5 only works for 13.5+ (including 14+).