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

output: "export" – Unable to export static HTML files for dynamic routes #53528

Closed
1 task done
crs1138 opened this issue Aug 3, 2023 · 2 comments
Closed
1 task done
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked

Comments

@crs1138
Copy link

crs1138 commented Aug 3, 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: x64
      Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:21:56 PDT 2023; root:xnu-8796.141.3~6/RELEASE_X86_64
    Binaries:
      Node: 18.15.0
      npm: 9.5.0
      Yarn: 3.5.0
      pnpm: N/A
    Relevant Packages:
      next: 13.4.12
      eslint-config-next: N/A
      react: N/A
      react-dom: N/A
      typescript: N/A
    Next.js Config:
      output: N/A

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

Static HTML Export (output: "export")

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

https://github.com/crs1138/nextjs-reproduction-output-export

To Reproduce

  1. Install all dependencies by running yarn
  2. yarn build
  3. php -S localhost:9001 -t ./out
  4. In browser navigate to http://localhost:9001/crs

Describe the Bug

This is similar to the problem described at #48022 with the difference that I am NOT trying to get the pages to generate on the client side but using the server components.

Route (app)                                Size     First Load JS
┌ ○ /                                      144 B          78.4 kB
└ ● /[slug]                                144 B          78.4 kB
+ First Load JS shared by all              78.2 kB
  ├ chunks/577-df9cece816524ea8.js         25.9 kB
  ├ chunks/d203b3d2-b46a1724b277c296.js    50.5 kB
  ├ chunks/main-app-65354122b08a6c70.js    215 B
  └ chunks/webpack-bf1a64d1eafd2816.js     1.61 kB

Route (pages)                              Size     First Load JS
─ ○ /404                                   182 B          75.8 kB
+ First Load JS shared by all              75.6 kB
  ├ chunks/framework-ef9abeff5a10c2f8.js   45 kB
  ├ chunks/main-c64c5a20bceb8890.js        28.8 kB
  ├ chunks/pages/_app-3ace18660f5d57f8.js  195 B
  └ chunks/webpack-bf1a64d1eafd2816.js     1.61 kB

○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)

Expected Behavior

I expect a static HTML file out/crs.html to be generated. This does not happen. Instead the following files appear in the /out folder:

out
├── 404.html
├── _next
│   ├── WBMVaM6MZcGR-A5r-ShoE
│   └── static
│       ├── WBMVaM6MZcGR-A5r-ShoE
│       │   ├── _buildManifest.js
│       │   └── _ssgManifest.js
│       └── chunks
│           ├── 577-df9cece816524ea8.js
│           ├── app
│           │   ├── [slug]
│           │   │   └── page-05a8d47b86b26f01.js
│           │   ├── layout-b135699092b7475d.js
│           │   └── page-fa049ba0ad39f926.js
│           ├── d203b3d2-b46a1724b277c296.js
│           ├── framework-ef9abeff5a10c2f8.js
│           ├── main-app-65354122b08a6c70.js
│           ├── main-c64c5a20bceb8890.js
│           ├── pages
│           │   ├── _app-3ace18660f5d57f8.js
│           │   └── _error-d1507c45b2aed998.js
│           ├── polyfills-78c92fac7aa8fdd8.js
│           └── webpack-bf1a64d1eafd2816.js
├── favicon.ico
├── index.html
├── index.txt
└── mock-data.json

When I try to serve the content of the out folder (eg. php -S localhost:9001 -t ./out) and navigate to http://localhost:9001/crs I should see the same result as if I do that in development
image

Instead I get a blank screen:
image

This is just a very simplified use-case, In the real life, there is a list of pages provided by decap-cms and I need these to be generated as static HTML files according to the slug provided by the CMS. I have no need for client-side data fetching. All the data necessary for the pages are provided in the server component.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@crs1138 crs1138 added the bug Issue was opened via the bug report template. label Aug 3, 2023
@balazsorban44 balazsorban44 added area: app App directory (appDir: true) area: export labels Aug 3, 2023
@balazsorban44
Copy link
Member

balazsorban44 commented Aug 3, 2023

Hi, the issue is that your generateStaticParams returns the wrong format. I.e. there is no params object.

export async function generateStaticParams() {
-  return [{ params: { slug: "crs" } }];
+  return [{ slug: "crs" }];
}

See: https://nextjs.org/docs/app/api-reference/functions/generate-static-params#returns

We have a test case for this here:

https://github.com/vercel/next.js/blob/canary/test/integration/app-dir-export/test/dynamicpage-prod.test.ts

https://github.com/vercel/next.js/blob/canary/test/integration/app-dir-export/app/another/%5Bslug%5D/page.js

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 Aug 18, 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. locked
Projects
None yet
Development

No branches or pull requests

2 participants