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

thank you! it works!

Hello, I’ve been trying to fix this issue on my companies site all day. I’ve tried every variation and combination of things suggested here. The prebuild script, adding the env variable, using netlify/plugin-nextjs at the version you suggested. our next is latest, react is latest, react-dom is latest. Any help would be very appreciated.

This solved it for me, brilliant

I have encountered this issue of 500 internal server error with my two deployed sites and managed to resolve it by running this line:

npm install -D @netlify/plugin-nextjs@4.37.4

I honestly do not know what causing the issue and if this is a long term solution but i think it works for now!

We’re experiencing this with "next": "13.4.19" using app router.

Root page.js loads fine but even a simple directory/page.js is having this issue when loaded by itself. It does work however if navigated to from a next link from the root page…

Any update?

UPDATE:

We were able to resolve by adding the prebuild script and downgrading next to 13.4.9

Add "prebuild": "node prebuild.js" to package.json scripts

Add prebuild.js

console.log("********* PREBUILDING");
const path = require("node:path");
const fs = require("fs");
const baseDir = process.cwd();

const prebuildScripts = async () => {
  const file = path.join(
    baseDir,
    "/node_modules",
    "next/dist/server/require-hook.js"
  );

  const content = await fs.promises.readFile(file, "utf-8");
  await fs.promises.writeFile(
    file,
    content.replace(
      "if (process.env.__NEXT_PRIVATE_PREBUNDLED_REACT) {",
      "if (true) {"
    )
  );
};

prebuildScripts();
1 Like

Your solution works for me too! !!
In my case only page witch is server-side rendered at runtime returned 500 error, but only when loaded directly (i.e when refreshing). When navigated by link from site menu it works fine.
Thank you, great job.

facing same issue with next 13.4.19

site Id: 32c3e9ed-88e5-49ed-85fc-322bb1e31aa9

Lemme know how long will it take to update it.

There’s nothing to update.

Hello, just want to thank you for all your support. I was having the issue described in this thread, here’s what i did:

  • Next is at 13.3.1

  • @netlify/plugin-nextjs is at 4.36.1

  • Set experimental mode to “true” on next.config.js (below for people just starting out like myself):
    this is my next.config.js file:

/** @type {import(‘next’).NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}

module.exports = nextConfig

With these changes, app is currently deployed and working! I’m a true beginning at this, started on netlify yesterday, with Nextjs a week ago. So if I can deploy a website, i don’t see why others won’t be able to!

Thank you again for all your help, your responses along this thread helped me a lot in finding the right configuration. I’m not saying people have to do exactly what I did, maybe they can do without setting the experimental mode to true. Just sharing what worked for me

Best wishes!

1 Like

can you add to my site

site id: 2f5a9c5a-226e-49da-8aa3-d937c18875af

can you add to my site

site id: 8559efa8-d015-4ebb-b9cb-b60f9e18205c

is getting this site id added still needed for fixing something???

No. I’d guess, these users are not reading the entire thread and probably just leaving their site IDs by reading the first few messages.

To be clear, leaving those IDs here is not going to solve anything.

1 Like

Wondering if anyone has made progress on getting this to work, for me it draft mode.

Starting to think of seeing if setting up /preview routes

@hrishikesh so what is the solution here? I’ve read the entire thread I am still not sure what to do.

We are running Next 13.4.11 and have @netlify/plugin-nextjs 4.40.1 but still seeing the issue. The id of the site is ce6706f0-8d29-4281-8088-9e9fd515f088

We were able to fix it by upgrading next.js to 13.5.6

There’s no solution here. Next.js 13.5 has its own set of issues: Runtime.ImportModuleError - Error: Cannot find module 'styled-jsx/style' - #16 by hrishikesh

Yeah. It fixed our app that uses app router but all other apps that still uses pages stopped working

So helpful, thank you so much