next.js: [NEXT-1260] /app/not-found broken in standalone mode

Verify canary release

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

Provide environment information

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.15.0
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: 8.3.1
    Relevant packages:
      next: 13.4.8-canary.1
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A

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

App directory (appDir: true), Standalone mode (output: “standalone”)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/klarstrup/next.js-repro-repo/tree/ERR_PACKAGE_PATH_NOT_EXPORTED

To Reproduce

Build and run the app: npm i && npm run build && node ./.next/standalone/server.js

Request any path on the server, http://localhost:3000/ is a good choice.

Describe the Bug

any 404 page results in a bunch of failing script requests which result in ERR_PACKAGE_PATH_NOT_EXPORTED spam in server output:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './server.edge' is not defined by "exports" in /next.js-repro-repo/.next/standalone/node_modules/react-dom/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:697: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 /Users/io/code/my-app/.next/standalone/node_modules/next/dist/server/require-hook.js:196:36
    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'
}

Expected Behavior

no failing script requests and ERR_PACKAGE_PATH_NOT_EXPORTED spam in server output

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

From SyncLinear.com | NEXT-1260

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 6
  • Comments: 27 (8 by maintainers)

Commits related to this issue

Most upvoted comments

This is not fixed as of #51611/next@13.4.8-canary.1

But as of #51506/next@13.4.7-canary.4 the 500 errors look like this on the backend 🤔

Error: connect ECONNREFUSED ::1:59104
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 59104
}

Hi, we hear you loud. As this bug is not fixed yet as the issue is still opening. We’ll post update once it’s closed with a PR or certain solution. No need to keep bumping it with comments, we’ll working on it, thanks 😄

We noticed that it’s the existence of a not-found.jsx file in our app directory that’s causing this issue. If we remove the not-found.jsx file and we add a root page.jsx, we don’t see the exception.

Example fix at https://github.com/klarstrup/next.js-repro-repo/pull/1 Also might be related to https://github.com/vercel/next.js/issues/49796

@klarstrup Thanks for checking it’s missing in release log, manually added them back for now. I’ll follow up why it’s lost 🙏

@klarstrup #51887 should hopefully resolve this issue 😃 This is likely due to Node.js 17 changing how it resolves ‘localhost’, so it might not be reproducible in older versions of Node.js.

Can confirm this still applies as of next@13.4.5-canary.7

Sorry I sometimes forget to update the next info output in the main issue text.