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

[NEXT-1260] /app/not-found broken in standalone mode #50232

Closed
1 task done
klarstrup opened this issue May 23, 2023 · 27 comments · Fixed by #51172 or #51611
Closed
1 task done

[NEXT-1260] /app/not-found broken in standalone mode #50232

klarstrup opened this issue May 23, 2023 · 27 comments · Fixed by #51172 or #51611
Assignees
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked Output (export/standalone) Related to the the output option in `next.config.js`.

Comments

@klarstrup
Copy link

klarstrup commented May 23, 2023

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

@christianvuerings
Copy link
Contributor

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 klarstrup/next.js-repro-repo#1
Also might be related to #49796

@ChandanJal
Copy link

Hey There ✋ ! It is working absolutely fine in my device.

Operating System:

  • Platform: darwin
  • Arch: arm64
  • Version: Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000

Binaries:

  • Node: v18.16.0
  • npm: 9.5.1

Relevant packages:

  • next: 13.4.4-canary.4
  • eslint-config-next: N/A
  • react: 18.2.0
  • react-dom: 18.2.0
  • typescript: N/A

@klarstrup
Copy link
Author

still applies as of next@13.4.4-canary.11

@klarstrup
Copy link
Author

still applies as of next@13.4.4

@Rajaotix
Copy link

Try to do clear npm cache then npm install. It works for me

@klarstrup
Copy link
Author

Still applies as of next@13.4.5-canary.2 - in spite of both npm cache clear --force and rm -rf node_modules .next and so on.

@Inoir
Copy link

Inoir commented May 31, 2023

our is gone after setting absolute paths for everything on the server. so prefix with NEXT_PUBLIC_URL. Dunno if this is only one of the cause of this error. without we had the same issue

@klarstrup
Copy link
Author

@marcospassos
Copy link

Same here

@klarstrup
Copy link
Author

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

@huozhi huozhi added the linear: next Confirmed issue that is tracked by the Next.js team. label Jun 7, 2023
@huozhi huozhi self-assigned this Jun 7, 2023
@huozhi huozhi changed the title /app/not-found broken in standalone mode [NEXT-1260] /app/not-found broken in standalone mode Jun 7, 2023
@klarstrup
Copy link
Author

klarstrup commented Jun 7, 2023

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.

@huozhi
Copy link
Member

huozhi commented Jun 7, 2023

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 😄

@klarstrup
Copy link
Author

Sorry, it wasn't really my impression that this had been triaged at all and I wanted to make sure the relevancy was apparent when you eventually got to it.

@kodiakhq kodiakhq bot closed this as completed in #51172 Jun 12, 2023
kodiakhq bot pushed a commit that referenced this issue Jun 12, 2023
Fixes #50232

Passing down the private env into `'render-server'` module to pick up the proper react with require-hook in standalone server
fix NEXT-1260
@jamiter
Copy link

jamiter commented Jun 16, 2023

@klarstrup, just curious if this is now fixed for you.

@huozhi huozhi reopened this Jun 19, 2023
@klarstrup
Copy link
Author

@klarstrup, just curious if this is now fixed for you.

Yes and no, it is broken in a new way in 13.4.7-canary.1.

@kodiakhq kodiakhq bot closed this as completed in #51611 Jun 22, 2023
kodiakhq bot pushed a commit that referenced this issue Jun 22, 2023
Request data flow in the server

```
request ---> router worker (1) ---> ipc ---> render worker app (2)
                                                              |-----> render worker pages (3)
```

When it's hitting `_next/*` unmatched routes in standalone server, it will render 404, but when you hit `_next/*` it will render app not-found as the app router is always enabled, but router worker isn't set up with require-hook for proper built-in react version, then the app-render will fail with `./server.edge` exports not found error.

We detect if it's in the render worker, then do the app paths rendering instead of directly looking up for app paths in route worker. This could avoid unexpected accesses to the app-render

Fixes #51482 
Fixes #50232
Closes #51506
Reverts changes in #51172
fix NEXT-1260
@klarstrup
Copy link
Author

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
}

@huozhi
Copy link
Member

huozhi commented Jun 23, 2023

@klarstrup how did you bump to this network error? I tried your original reproduction from this issue with canary version it works for me

@klarstrup
Copy link
Author

No idea, this is with the repro repo above on the system described above:

io@Ios-MacBook-Pro my-app % git status   
On branch ERR_PACKAGE_PATH_NOT_EXPORTED
Your branch is up to date with 'origin/ERR_PACKAGE_PATH_NOT_EXPORTED'.

nothing to commit, working tree clean
io@Ios-MacBook-Pro my-app % rm -rf .next node_modules && npm i next@canary && npm run build && node ./.next/standalone/server.js

added 40 packages, and audited 42 packages in 2s

5 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

> build
> next build

- info Creating an optimized production build  
- info Compiled successfully
- info Linting and checking validity of types  
- info Collecting page data  
- info Generating static pages (3/3)
- info Finalizing page optimization  

Route (app)                                Size     First Load JS
─ ○ /_not-found                            0 B                0 B
+ First Load JS shared by all              77.6 kB
  ├ chunks/769-f51582f2b9b00a6b.js         25.2 kB
  ├ chunks/bce60fc1-49ee79ad31766ac6.js    50.5 kB
  ├ chunks/main-app-5537570c1c769cc0.js    217 B
  └ chunks/webpack-bf1a64d1eafd2816.js     1.61 kB

Route (pages)                              Size     First Load JS
─ ○ /404                                   182 B          75.4 kB
+ First Load JS shared by all              75.2 kB
  ├ chunks/framework-8883d1e9be70c3da.js   45 kB
  ├ chunks/main-f21a854e626768e2.js        28.4 kB
  ├ chunks/pages/_app-998b8fceeadee23e.js  195 B
  └ chunks/webpack-bf1a64d1eafd2816.js     1.61 kB

○  (Static)  automatically rendered as static HTML (uses no initial props)

Listening on port 3000 url: http://localhost:3000
Error: connect ECONNREFUSED ::1:49756
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 49756
}
Error: connect ECONNREFUSED ::1:49756
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 49756
}
^C%                                                                                                                                                                       
io@Ios-MacBook-Pro my-app % npx next info                                                                                       

    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

io@Ios-MacBook-Pro my-app % 

@DuCanhGH
Copy link
Contributor

DuCanhGH commented Jun 27, 2023

@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.

@ghost91-
Copy link

ghost91- commented Jun 28, 2023

We have the same issue, using Next.js 13.4.7 and Node.js 18.16.0. With Node.js 16, it seems to work correctly, so it seems like it's the other way round and it's broken in newer versions of Node.js. That's also what the PR says, so I suppose it's just worded the wrong way round here.

@klarstrup
Copy link
Author

Inexplicably fixed for me as of next@13.4.9-canary.3 🤷‍♀️ Can't figure out which change in that version actually did the trick

@DuCanhGH
Copy link
Contributor

DuCanhGH commented Jul 7, 2023

@klarstrup the default host was changed to 127.0.0.1, which, uh, was quite crazy a change...

@klarstrup
Copy link
Author

Oh I found the PR now #52283

It was not mentioned in the release notes :/ @shuding

@shuding
Copy link
Member

shuding commented Jul 7, 2023

That was included in the canary release, although it should be part of the release note.

@klarstrup
Copy link
Author

Not as anything resembling "Use 127.0.0.1 as the default host for the standalone server" at least, I think something might've gone awry generating the release note.

@huozhi
Copy link
Member

huozhi commented Jul 7, 2023

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

@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 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 added the locked label Aug 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 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. linear: next Confirmed issue that is tracked by the Next.js team. locked Output (export/standalone) Related to the the output option in `next.config.js`.
Projects
None yet