Skip to content

Routing error in dev mode: TypeError: Cannot read property 'includes' of undefined (take two) #38047

Closed

Description

@JoshuaKGoldberg

Verify canary release

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

Provide environment information

  Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Fri Apr 2 22:23:49 UTC 2021
    Binaries:
      Node: 18.2.0
      npm: 8.9.0
      Yarn: 1.22.19
      pnpm: 6.11.0
    Relevant packages:
      next: 12.1.7-canary.48
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome, but n/a

How are you deploying your application? (if relevant)

n/a

Describe the Bug

#16874 is still impacting users. I have a repro! If the network request to /_next/static/development/_devPagesManifest.json fails for any reason, the Next.js dev application crashes with:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'includes')
    at resolveDynamicRoute (router.js?8684:1314:16)
    at _callee$ (router.js?8684:969:31)
    at tryCatch (runtime.js?ecd4:45:16)
    at Generator.invoke [as _invoke] (runtime.js?ecd4:274:1)
    at prototype.<computed> [as next] (runtime.js?ecd4:97:1)
    at asyncGeneratorStep (_async_to_generator.js?0e30:23:1)
    at _next (_async_to_generator.js?0e30:12:1)

Expected Behavior

Next.js should be resilient to that manifest failing to load.

I took a dive into the source code and there are some spicy TypeScript shenanigans happening 😄. And some TODOs about handling this correctly! #38046 is a draft PR showing what I'd suggest doing to resolve this issue.

  1. The crash is coming from inside the framework, on if (pages.includes(fsPathname))
  2. pages is a parameter of resolveRewrites
  3. In calls to resolveRewrites, pages comes from this.pageLoader.getPageList()
  4. getPageList doesn't properly handle the case of fetch(.../_next/static/development/_devPagesManifest.json) failing: return this.promisedDevPagesManifest! has a // TODO Remove this assertion as this could be undefined comment

Link to reproduction

https://stackblitz.com/edit/vercel-next-js-flnphe?file=pages%2Findex.tsx

(really, any Next.js app with a Link can demonstrate this issue)

To Reproduce

  1. Start any Next.js app in development mode
  2. Add a <Link> somewhere on the page
  3. Visit localhost:3000 (or equivalent) in Chrome (or equivalent)
  4. In the network tab, right click on the _devPagesManifest.json request and select Block request url
  5. Refresh the page

Step 3 is the easiest way to simulate any of the reasons why that URL wouldn't be accessible that are mentioned in #16874. Apparently nginx configurations are more common culprits. Anecdotally I think I've seen this on CI runs that have flaky network layers (both GitHub Actions and CircleCI).

Activity

  1. added
    bugIssue was opened via the bug report template.
    on Jun 27, 2022
  2. added a commit that references this issue on Aug 7, 2022
    963585a
  3. github-actions commented on Sep 7, 2022

    @github-actions
    Contributor

    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.

  4. locked as resolved and limited conversation to collaborators on Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions