Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package subpath './server.edge' is not defined by "exports" #48948

Closed
1 task done
medonat opened this issue Apr 28, 2023 · 24 comments · Fixed by #49101 or #49168
Closed
1 task done

Package subpath './server.edge' is not defined by "exports" #48948

medonat opened this issue Apr 28, 2023 · 24 comments · Fixed by #49101 or #49168
Assignees
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.

Comments

@medonat
Copy link

medonat commented Apr 28, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Enterprise
    Binaries:
      Node: 16.18.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.3.2-canary.12
      eslint-config-next: 13.3.1
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue

https://github.com/medonat/nextjs-revalidate-test

To Reproduce

  1. Clone the repository
  2. npm install
  3. npm run build
  4. npm run start
  5. Open localhost:3000
  6. The cat fact shouldn't change onreload
  7. Make a POST request: localhost:3000/api/revalidate
  8. There should be an error 500 and no update if you reload localhost:3000
  9. Checkout branch 13.3.0 - and repeat the procedure to see that it worked in 13.3.0

Describe the Bug

ISR does not work. Stale data is displayed after calling revalidate.

Error in console:
TypeError: Cannot set properties of undefined (setting 'current') at ue (C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\compiled\react-dom\cjs\react-dom-server.edge.production.min.js:113:42) at C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\compiled\react-dom\cjs\react-dom-server.edge.production.min.js:151:127 at new Promise (<anonymous>) at Object.exports.renderToReadableStream (C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\compiled\react-dom\cjs\react-dom-server.edge.production.min.js:151:53) at C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\server\node-web-streams-helper.js:195:117 at NextTracerImpl.trace (C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\server\lib\trace\tracer.js:86:20) at renderToInitialStream (C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\server\node-web-streams-helper.js:195:37) at C:\Users\daniel.hufler\Documents\code\revalidatetest\node_modules\next\dist\server\app-render\app-render.js:918:92

Expected Behavior

Revalidate should work like it did in previous versions (e.g. 13.3.0)

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

next start

@medonat medonat added the bug Issue was opened via the bug report template. label Apr 28, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Apr 28, 2023
@LotharVM
Copy link

LotharVM commented May 1, 2023

Facing the exact the same issue here, On-demand revalidation doesn't seem to be working anymore since v13.3.0.. Any update on this @timneutkens ?

@Djboy08
Copy link

Djboy08 commented May 1, 2023

I get the same issue

@jwalcher
Copy link

jwalcher commented May 1, 2023

i can confirm the issue starts with v13.3.2-canary.7

@xFoolCode
Copy link

Can confirm ,
Got the same issue on my local machine

    Operating System:
      Platform: linux
      Arch: x64
      Version: #202303130630~1681329778~22.04~d824cd4 SMP PREEMPT_DYNAMIC Wed A
    Binaries:
      Node: 19.9.0
      npm: 9.6.3
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.3.4
      eslint-config-next: 13.3.4
      react: 18.2.0
      react-dom: 18.2.0
TypeError: Cannot set properties of undefined (setting 'current')
    at ue (/home/thegreatlogician/Projects/app-next/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.edge.production.min.js:113:42)
    at /home/thegreatlogician/Projects/app-next/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.edge.production.min.js:151:127
    at new Promise (<anonymous>)
    at exports.renderToReadableStream (/home/thegreatlogician/Projects/app-next/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.edge.production.min.js:151:53)
    at /home/thegreatlogician/Projects/app-next/node_modules/next/dist/server/node-web-streams-helper.js:195:117
    at NextTracerImpl.trace (/home/thegreatlogician/Projects/app-next/node_modules/next/dist/server/lib/trace/tracer.js:86:20)
    at renderToInitialStream (/home/thegreatlogician/Projects/app-next/node_modules/next/dist/server/node-web-streams-helper.js:195:37)
    at /home/thegreatlogician/Projects/app-next/node_modules/next/dist/server/app-render/app-render.js:937:92

@shuding shuding self-assigned this May 2, 2023
@LotharVM
Copy link

LotharVM commented May 2, 2023

After upgrading to canary v13.3.5-canary3, the error changed to

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /Users/user/Documents/folder/client/frontend/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:729:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at /Users/lothar-bravoure/Documents/_FTP/paradiso/frontend/node_modules/next/dist/server/require-hook.js:180:36
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'

Just in case it helps :)

@shuding
Copy link
Member

shuding commented May 2, 2023

Thanks, I've identified the cause and am working on a fix right now.

@khuezy
Copy link
Contributor

khuezy commented May 3, 2023

Was hoping canary.4 would fix it but it didn't :(

timneutkens pushed a commit that referenced this issue May 3, 2023
Currently we invoke the revalidate request directly in the current
server when `res.revalidate()` is called. However app needs to be
rendered in a separate worker so this results in an error of React. This
PR fixes it by sending the request via IPC so the main process will
delegate that to the correct render worker.

Closes #48948.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@khuezy
Copy link
Contributor

khuezy commented May 3, 2023

@shuding can you reopen the ticket please, the latest canary.6:

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

@karlhorky
Copy link
Contributor

karlhorky commented May 3, 2023

Yeah I'm also seeing this Error: Package subpath './server.edge' is not defined by "exports" in node_modules/react-dom/package.json with next@13.3.5-canary.6 in a monorepo which has other packages using non-experimental react-dom versions (maybe this 18.2.0 below is the version from those other packages?)

@shuding should we open a new issue to track this?

$ cat node_modules/react-dom/package.json
{
  "name": "react-dom",
  "version": "18.2.0",
  "description": "React package for working with the DOM.",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/facebook/react.git",
    "directory": "packages/react-dom"
  },
  "keywords": [
    "react"
  ],
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/facebook/react/issues"
  },
  "homepage": "https://reactjs.org/",
  "dependencies": {
    "loose-envify": "^1.1.0",
    "scheduler": "^0.23.0"
  },
  "peerDependencies": {
    "react": "^18.2.0"
  },
  "files": [
    "LICENSE",
    "README.md",
    "index.js",
    "client.js",
    "profiling.js",
    "server.js",
    "server.browser.js",
    "server.node.js",
    "test-utils.js",
    "cjs/",
    "umd/"
  ],
  "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"
  },
  "browser": {
    "./server.js": "./server.browser.js"
  },
  "browserify": {
    "transform": [
      "loose-envify"
    ]
  }
}

@khuezy
Copy link
Contributor

khuezy commented May 3, 2023

@karlhorky Can you open a ticket please? I think it warrants a new one since it's different than the original ticket. Thanks.

@karlhorky
Copy link
Contributor

karlhorky commented May 3, 2023

Right - it is not the same as the original issue - it's the same error message that you posted in your comment above and @LotharVM posted in their comment.

@shuding shuding reopened this May 3, 2023
@shuding shuding changed the title ISR - revalidate no longer working - TypeError: Cannot set properties of undefined (setting 'current') Package subpath './server.edge' is not defined by "exports" May 3, 2023
@karlhorky
Copy link
Contributor

karlhorky commented May 3, 2023

@shuding here's a repro, seems like it's caused by custom servers:

CodeSandbox Demo (start server using npm run dev or node server.mjs):

Changes to reproduction template:

// server.mjs
import { createServer } from "node:http";
import { parse } from "node:url";
import next from "next";

const dev = process.env.NODE_ENV !== "production";
const hostname = "localhost";
const port = 3000;
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();

app.prepare().then(() => {
  createServer(async (req, res) => {
    try {
      await handle(req, res, parse(req.url, true));
    } catch (err) {
      console.error("Error occurred handling", req.url, err);
      res.statusCode = 500;
      res.end("internal server error");
    }
  })
    .once("error", (err) => {
      console.error(err);
      process.exit(1);
    })
    .listen(port, () => {
      console.log(`> Ready on http://${hostname}:${port}`);
    });
});

Screenshot 2023-05-03 at 20 52 57

shuding added a commit that referenced this issue May 3, 2023
Fixes #48948
([repro](#48948 (comment))).
When running inside a custom server with app dir, we should always opt
into the prebundled React with correct channels.

Thanks @karlhorky for help testing it!

Fixes #49169 too.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@karlhorky
Copy link
Contributor

karlhorky commented May 4, 2023

I can confirm next@13.3.5-canary.8 (first version including PR #49168) is working with custom servers 🎉 Thanks @shuding !!

CodeSandbox: https://codesandbox.io/p/sandbox/quirky-bell-o5tl8l?file=%2Fserver.mjs

Screenshot 2023-05-04 at 11 42 39

@klarstrup
Copy link

klarstrup commented May 4, 2023

Seeing this error with a output: "standalone" server on next@13.3.5-canary.9 :[

@daszkowski
Copy link

Have same error (for next@13.4.0) - Package subpath './server.edge' is not defined by "exports" - for On-demand Revalidation using res.revalidate([url])

@LotharVM
Copy link

LotharVM commented May 5, 2023

Also still facing this issue with 13.4.0:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /Users/user/Documents/folder/client/frontend/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:453:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:729:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at /Users/user/Documents/folder/client/frontend/node_modules/next/dist/server/require-hook.js:180:36
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Error: Invalid response 500
    at NextNodeServer.revalidate (/Users/user/Documents/folder/client/frontend/node_modules/next/dist/server/next-server.js:1208:19)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Server.<anonymous> (/Users/user/Documents/folder/client/frontend/node_modules/next/dist/server/lib/server-ipc/index.js:54:30)

@briankulp
Copy link

Running into the same issue on 13.4.1 with the output: 'standalone' setting as well.

@berekuk
Copy link
Contributor

berekuk commented May 5, 2023

I had this issue on 13.4.0 when I deployed on Vercel (local next dev was fine). I didn't use output: 'standalone' or revalidation.

Removing react and react-dom (18.2.0) from explicit dependencies in package.json helped.

@jwalcher
Copy link

jwalcher commented May 6, 2023

the error persists for in 13.4.2, both local and self-hosted. Do we reopen the ticket @shuding or create a new one?

@shuding
Copy link
Member

shuding commented May 6, 2023

@jwalcher opening a new one with a minimal reproduction repo will definitely help, thanks!

@jwalcher
Copy link

jwalcher commented May 9, 2023

I tried around a bit, and in my current setup the error only appears when the revalidation path gets rewritten by middleware. However, I am still calling res.revalidate from api route instead of using route handler in app directory. If the error persists after complete migration, I will post a new report. Thanks!

@jwalcher
Copy link

Whoever is still following this: The new revalidatePath function from next/cache to be used in route handlers in the app directory does not work for me on dynamically generated routes, and fails to rebuild the page at the first refresh even on static routes.

@shuding: I have opened an issue #49955 reporting the problems with res.revalidate through middleware, and those with revalidatePath for dynamically generated routes.

Minimal code is at https://github.com/jwalcher/revalidation

ijjk added a commit that referenced this issue May 18, 2023
This removes the previous handling for the prebundled react env we were
setting in favor of vercel/vercel#9974

We need to wait to land this until
vercel/vercel#9974 has been rolled

Fixes: #49169
Fixes: #49753
x-ref: #48948
@jwalcher
Copy link

jwalcher commented Jun 4, 2023

@jwalcher opening a new one with a minimal reproduction repo will definitely help, thanks!

@shuding Please could someone take another look at this, perhaps through the issue #50464

The Package subpath './server.edge' is not defined by "exports" error persists during on-demand revalidation when the middleware-invoke flag is set on a path in the app directory (without middleware getting invoked per se during revalidation). This might well be a router issue, but it might also arise later during re-render.

hydRAnger pushed a commit to hydRAnger/next.js that referenced this issue Jun 12, 2023
This removes the previous handling for the prebundled react env we were
setting in favor of vercel/vercel#9974

We need to wait to land this until
vercel/vercel#9974 has been rolled

Fixes: vercel#49169
Fixes: vercel#49753
x-ref: vercel#48948
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.
Projects
None yet