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

HMR Not Working for New Files in pages and server Directories within Docker Environment #26180

Open
lafllamme opened this issue Mar 10, 2024 · 3 comments

Comments

@lafllamme
Copy link

lafllamme commented Mar 10, 2024

Environment

Reproduction example for the described use case (pages & api functionality):
https://stackblitz.com/edit/github-drgy5q?file=nuxt.config.ts

Reproduction

Environment

Nuxt Version: "nuxt": "^3.10.3",
Docker Version: 4.28.0 (139021)
Operating System: Windows 11 Version 10.0.22631 Build 22631, MacOS Ventura (latest official)

Describe the bug

We are encountering an issue with Hot Module Replacement (HMR) within a Docker environment on both MacOS and Windows (using WSL 2.0). Specifically, the problem involves adding new files to the pages and server directories of our Nuxt 3 application. Changes to existing files, including components, styles, and text contents, are correctly recognized and processed. However, new files added for routes in pages or for APIs in server are not detected until the Docker container or the Nuxt server is restarted.

Steps to Reproduce

  1. Start the Nuxt application in a Docker container.
  2. Add a new file to the pages directory to create a new route.
  3. Attempt to access the new route or wait for HMR to detect the change.
  4. Repeat steps for adding a new file in the server directory for an API.

Expected Outcome: Changes or new files should be recognized by HMR and applied immediately.

Actual Outcome: New files are only recognized and processed after restarting the Docker container or Nuxt server.

Potential Causes

It appears that the HMR configuration or Docker settings may not be correctly set up to detect new files in the filesystem. The issue could be related to the watch configuration or specific settings for Docker environments that affect filesystem change detection.
Attempted Solutions

  • Enabled polling in the Vite configuration (as shown in the provided code snippet).
  • Tried various host and HMR settings.

Unfortunately, these approaches did not resolve the issue.

This is my docker-compose.yml (lies at same-root level):

version: '3.8'
services:
  app-nuxt:
    image: oven/bun:latest # The image name
    container_name: app-nuxt
    ports:
      - "3000:3000"
      - "24678:24678"
    volumes:
      - .:/app
    working_dir: /app # Set working directory to where your app is
    restart: always
    command: sh -c "bun install && bun run dev"
    environment: # Correct command to install dependencies and run dev server  
      - NODE_ENV=development
    user: bun

This is corresponding nuxt.config.ts with adjustments for local dev server (page / server changes not reflecting):

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
    modules: [
        '@unocss/nuxt'
    ],
    devtools: {
        enabled: true,

        timeline: {
            enabled: true
        }
    },
    app: {
        pageTransition: {
            name: 'page',
            mode: 'out-in'
        }
    },
    //pages: true,
    //fix issue for docker not reflecting changes
    vite: {
        server: {
            host: '0.0.0.0',
            hmr: {
                protocol: 'ws',
                host: 'localhost'
            },
           /* client: {
                webSocketURL: 'ws://0.0.0.0:8080/ws',
            },*/
            watch: {
                usePolling: true,
                interval: 1000,
            },
        },
    },
})

Additional context

No response

Logs

No response

Copy link

stackblitz bot commented Mar 10, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@lafllamme
Copy link
Author

This issue might be related to this issue here:

#23219

I still face the issue, that inside docker, regardless of package manager and os, changes under /server are not reflected.

@Dino-Kupinic
Copy link

I had this issue months ago and gave up nuxt+docker
issues with nuxt/pinia+docker aswell

@danielroe danielroe removed the 3.x label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants