The fact that the app is trying to load JavaScript chunks from the file system (file://) seems wrong to me. In a typical Next.js development environment, JavaScript chunks are served via HTTP, e.g. as http://localhost:3000/_next/static/chunks/..... That kind of path (file:///app/.next/...) may indicate that something has gone wrong with how the app is being run inside Docker.
Most likely, it’s trying to execute frontend code before the dev server is ready, or the chunk paths are being resolved incorrectly because of how the container is configured. You might be mounting or copying .next in a way that confuses the runtime.
Try removing .next entirely (rm -rf .next) and let the dev server rebuild it from scratch inside the container, not copied from your host.
I think that the issue is that you’re mounting an external volume to /app/.next, but that volume is empty. This overwrites the internal .next directory that Next.js needs to serve chunks, leading to the file:// errors you’re seeing.
To fix:
Remove this line from your docker-compose file: - portal-next:/app/.next.
Delete any .next directory on your host: rm -rf /home/Projects/portal/.next
Rebuild the container: docker-compose build --no-cache
And restart the service: docker-compose up
Let the dev server create and manage .next inside the container. That should hopefully resolve the chunk loading problem.
Hello,
Thanks again.
But it’s the exact opposite. If I remove that line, the .next directory is created on the host, not the container. Meanwhile, the .dockerignore file prevents the .next directory on the host from replacing the .next directory in the container.
Contents of the .next directory in the container:
$ ls .next
app-build-manifest.json server
build-manifest.json static
cache trace
package.json types
react-loadable-manifest.json
I think that the reason .next is showing up on your host with root permissions is because you’re bind-mounting the entire project folder with this line:
- /home/Projects/portal:/app
That causes anything created inside the container to appear on your host, which leads to permission issues and possibly chunk loading problems.