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

Build and dev behave differently when generating static route parameters #54730

Open
1 task done
ardunster opened this issue Aug 29, 2023 · 0 comments
Open
1 task done
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation. SWC Related to minification/transpilation in Next.js.

Comments

@ardunster
Copy link

Verify canary release

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

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 19.6.0: Tue Jun 21 21:18:39 PDT 2022; root:xnu-6153.141.66~1/RELEASE_X86_64
    Binaries:
      Node: 19.3.0
      npm: 9.4.2
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.20-canary.12
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

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

App Router, Routing (next/router, next/navigation, next/link), SWC transpilation

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

https://github.com/ardunster/nextjs-ssr

To Reproduce

  1. Check out commit d213ec287625328019c261328fa6ce435779797a.
  2. Run next dev or its alias npm run dev. Everything works.
  3. Run next build or its alias npm run build. Get error:
Error occurred prerendering page "/articles/2023%2Fnewest-article". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
    at Object.openSync (node:fs:576:10)
    at Object.readFileSync (node:fs:452:35)
    at getArticle (/Users/user/Development/nextjs-ssr/.next/server/chunks/399.js:77:72)
    at ArticleBySlug (/Users/user/Development/nextjs-ssr/.next/server/app/articles/[...slug]/page.js:555:97)
    at preloadComponent (/Users/user/Development/nextjs-ssr/node_modules/next/dist/server/app-render/preload-component.js:23:22)
    at /Users/user/Development/nextjs-ssr/node_modules/next/dist/server/app-render/app-render.js:615:101
    at async createComponentTree (/Users/user/Development/nextjs-ssr/node_modules/next/dist/server/app-render/app-render.js:615:29)
    at async /Users/user/Development/nextjs-ssr/node_modules/next/dist/server/app-render/app-render.js:543:91
    at async Promise.all (index 0)
    at async createComponentTree (/Users/user/Development/nextjs-ssr/node_modules/next/dist/server/app-render/app-render.js:501:38)
- info Generating static pages (11/11)

> Export encountered errors on following paths:
        /articles/[...slug]/page: /articles/2023%2Fnesty%2Farticle1-copy
        /articles/[...slug]/page: /articles/2023%2Fnewest-article

Describe the Bug

The next dev and next build operations do not handle passing the static route generation to the component in the same way. next dev passes the route strings with / included, next build passes them transformed to %2F, causing the file paths to not work.

I believe the fix implemented in commit 1d4177fb74acc20360311c7f5ffe6f747587c8fd (splitting the string by path.sep instead of using the encoded / characters, and recombining the segments in the file retrieval code) is more accurate to how the generateStaticParams path is supposed to work, and is a better pattern to use, so the fact that next build fails here is not necessarily a bug; however, next dev working fine mislead me into thinking I had already solved a problem that I had not completely solved yet.

This stackoverflow question may also be related (answer is mine).

Expected Behavior

next dev should fail on any build step that next build fails on.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@ardunster ardunster added the bug Issue was opened via the bug report template. label Aug 29, 2023
@github-actions github-actions bot added Navigation Related to Next.js linking (e.g., <Link>) and navigation. SWC Related to minification/transpilation in Next.js. labels Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation. SWC Related to minification/transpilation in Next.js.
Projects
None yet
Development

No branches or pull requests

1 participant