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

I’m afraid v4.39.1 still has the same error

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /var/task/node_modules/react-dom/package.json

It’s kind of true - when you look at the package.json, it doesn’t have server.edge exported:

"exports": {
    ".": "./index.js",
    "./client": "./client.js",
    "./server": {
      "deno": "./server.browser.js",
      "worker": "./server.browser.js",
      "browser": "./server.browser.js",
      "default": "./server.node.js"
    },
    "./server.browser": "./server.browser.js",
    "./server.node": "./server.node.js",
    "./profiling": "./profiling.js",
    "./test-utils": "./test-utils.js",
    "./package.json": "./package.json"
  },

What site did you test this on? I’m checking the site you mentioned and it keeps giving me a 404.

EDIT: Nevermind, noticed that it was in a sub-directory.

@nick.howard would it be possible to share your repo?

I don’t think so, as it’s work I’m doing for a company, but I can share what breaks it.

I’m using a Prismic CMS and the @primicio/client package. It uses the native fetch under the hood, which is the fetch provided by NextJS in this instance.

When I call fetch without any next options, it works fine, since it’s generating static content. The problem comes when I provide the following options:

fetchOptions: {
  next: {
    revalidate: 60 * 60,
  }
}

The idea is that I want it to revalidate the content in an hour. In this instance, I see the error in the ISR Handler function.

I’ve also tried

fetchOptions: {
  cache: 'no-cache'
}

Which will never cache the response. In this instance, I see the error in the SSR Handler function.

I can also see server.edge is exported in the main branch of react-dom

But maybe the haven’t released it :person_shrugging:

Thanks for sharing. I’ve relayed that back to the devs!

1 Like

No problem. My thinking is that it’s not a Netlify-specific issue, and actually something that needs picking up with NextJS or the React team

We shall get a confirmation if that’s the case! :wink:

Based on the current analysis, v4.39.1 should have fixed most if not all use-cases. So yours currently appears to be an unknown or untested edge-case. Devs will now try to analyse and reproduce this further to see if they can find a solution or if it’s a React/Next.js issue as you feel.

I’m still getting a 500 server error on v.4.39.1. My project uses dynamic routes for i18n. Here’s my SSR handler log:

Jul 12, 09:54:03 AM: e52ee9f1 ERROR  Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /var/task/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:366:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:702:9)
    at resolveExports (node:internal/modules/cjs/loader:565:36)
    at Module._findPath (node:internal/modules/cjs/loader:634:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1061:27)
    at /var/task/.netlify/functions-internal/___netlify-handler/requireHooks.js:100:40
    at Module._load (node:internal/modules/cjs/loader:920:27)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

@estebanv is there a site we can check?

You can find the page at aquamanps.netlify.app, with site id: 934a7cb7-9e4a-44d6-a0e7-cafede075f9b

@hrishikesh any thoughts?

@hrishikesh can you check our site?
In my case i have 500 error in some req to api links.
Now in production we have correct deploy with downgraded “@netlify/plugin-nextjs”: “^4.36.1”,
But in new deploys we have 500 errors.
And upgrade to 4.39.1 didin’t help us.

if need any additional info i can send you.

https://github.com/texttree/v-cana
https://deploy-preview-415--v-cana.netlify.app

Hey @alexzed,

I’m seeing this error in your API console:

This is completely un-related to this thread. It could be due to a plugin version roll-out on the split API paths, but that’s a separate issue. I’ll escalate this issue accordingly.

Thanks!
I will look forward to any solution from you on this issue

Maybe it will be easier for you from this information, now I have tried downgrade version 4.36.1 again - and everything works for me with this version, and with versions 4.38~4.39 I get errors.

I’m seeing the same issue with 4.39.1 on my site. The site id is 95b624a8-99c7-4ed4-8d54-ce77863bc823 and an example that triggers the error can be seen by causing a 404 on beehive.gay, e.g. https://beehive.gay/invalid

The latest deploy used 4.39.1 (deploy id 64af0f99c24927266a17e951)

@alexzed, could you try deploying again with any of the newset versions? The problem you were seeing yesterday should be resolved. Then, if you continue to receive the serve.edge error, we can discuss accordingly.

Thank you for the report @olivvybee, we’re investigating more use-cases. Once we release a new version to fix those, we will let you know so you can re-try.

@hrishikesh Yes, it really works! I am very glad that you helped me. It was very professional and fast!
v.4.39.1 works well
Thank you.

@hrishikesh I have some more information about what could be going wrong…

The error states the path .netlify/functions-serve/.unzipped/___netlify-odb-handler/node_modules/react-dom/package.json that does not have server.edge exported, which is correct.

However

It shouldn’t be looking there for it, it should be looking at the next bundled version of react-dom .netlify/functions-serve/.unzipped/___netlify-odb-handler/node_modules/next/dist/compiled/react-dom/package.json - which indeed has everything that is needed.

It looks like somewhere, I don’t know where, the handler is looking to the wrong react-dom for nextjs.

@nick.howard, thank you for that. But, for some context, this is all to do with React being absorbed into Next.js. For App Router, Next.js now uses an internal version of React (one of 2 versions that now come prebundled with Next and are not the same as latest , hence why react-dom doesn’t have server.edge included in its package.json exports). They actually monkey patch require to override where React is resolved from, based on whether the route is from app or pages. We’re trying to do the same but there’re so many edge cases.

1 Like

yes, I can see that it’s quite complex :slight_smile: