Description
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: #85-Ubuntu SMP Fri Jul 7 15:25:09 UTC 2023
Binaries:
Node: 18.15.0
npm: 9.5.0
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 13.4.15
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Next.js Config:
output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router
Link to the code that reproduces this issue or a replay of the bug
https://github.com/eide-1/sample-project
To Reproduce
Steps to Reproduce:
- Run the the project in a production environment by following the instructions in the README file
- Click on the "Go to Dynamic Route" button. You will be presented with an application error
- Right-click anywhere on the webpage and click "Inspect". The browser console will display the "ChunkLoadError"
Describe the Bug
I am currently working on upgrading an existing Next.js SPA that uses the pages router to the app router. The project is deployed using Docker and Nginx. However, I noticed that dynamic routes cause a "ChunkLoadError" when the SPA is deployed in a production environment. All pages (including dynamic routes) are functional in a development environment.
The dynamic route in question uses the "use client" directive. I noticed that if I remove the "use client" directive and any component or hook that requires it from the page, I can get it to render properly in production mode.
I created a sample project that uses the same tech stack as my current SPA to demonstrate the issue and I included the steps to reproduce the issue below.
I also found the following Stack Overflow question detailing a similar issue to the one I described above: In Next.js 13 using App Router, why can't I export dynamic routes with "use client"?
Expected Behavior
Dynamic routes should work in the production environment just like they used to under the pages router without causing a ChunkLoadError.
Which browser are you using? (if relevant)
Microsoft Edge 115.0.1901.203 (64-bit)
How are you deploying your application? (if relevant)
Docker/Nginx