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

Reload/refresh not working in v18 and v17 #22945

Open
3 of 4 tasks
poeck opened this issue Apr 22, 2024 · 20 comments
Open
3 of 4 tasks

Reload/refresh not working in v18 and v17 #22945

poeck opened this issue Apr 22, 2024 · 20 comments
Assignees
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug

Comments

@poeck
Copy link

poeck commented Apr 22, 2024

Current Behavior

When I serve my NestJS project in development and change a file, it reloads perfectly the first time. When I change the file again, it stop refreshing and does nothing. This also happens in a fresh project with npx create-nx-workspace my-workspace --preset=nest

Expected Behavior

It should refesh every time I change a file, not only the first time.

GitHub Repo

No response

Steps to Reproduce

  1. Create a new nest project npx create-nx-workspace my-workspace --preset=nest
  2. Run nx serve api
  3. Change a file
  4. See how it reloads
  5. Change the file again
  6. Nothing happens

Nx Report

NX   Report complete - copy this into the issue template

Node   : 18.18.2
OS     : linux-x64
pnpm   : 8.15.2

nx (global)        : 18.3.3
nx                 : 18.3.3
@nx/js             : 18.3.3
@nx/eslint         : 18.3.3
@nx/workspace      : 18.3.3
@nx/eslint-plugin  : 18.3.3
@nx/express        : 18.3.3
@nx/nest           : 18.3.3
@nx/next           : 18.3.3
@nx/node           : 18.3.3
@nx/web            : 18.3.3
@nx/webpack        : 18.3.3
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/next/plugin

Failure Logs

Daemon Log:

[NX Daemon Server] - 2024-04-22T19:14:18.253Z - Started listening on: /tmp/9e9a81d0946c1ff77af8/d.sock
[NX Daemon Server] - 2024-04-22T19:14:18.254Z - [WATCHER]: Subscribed to changes within: /home/paul/dev/jokedial (native)
[NX Daemon Server] - 2024-04-22T19:14:18.255Z - Established a connection. Number of open connections: 1
[NX Daemon Server] - 2024-04-22T19:14:18.255Z - Established a connection. Number of open connections: 2
[NX Daemon Server] - 2024-04-22T19:14:18.256Z - [REQUEST]: Client Request for Project Graph Received
[NX Daemon Server] - 2024-04-22T19:14:18.313Z - [REQUEST]: Updated workspace context based on watched changes, recomputing project graph...
[NX Daemon Server] - 2024-04-22T19:14:18.313Z - [REQUEST]: 
[NX Daemon Server] - 2024-04-22T19:14:18.313Z - [REQUEST]: 
[NX Daemon Server] - 2024-04-22T19:14:19.723Z - [REQUEST]: Responding to the client. project-graph
[NX Daemon Server] - 2024-04-22T19:14:19.725Z - Time taken for 'total for creating and serializing project graph' 1466.750123001635ms
[NX Daemon Server] - 2024-04-22T19:14:19.725Z - Closed a connection. Number of open connections: 1
[NX Daemon Server] - 2024-04-22T19:14:19.727Z - Done responding to the client project-graph
[NX Daemon Server] - 2024-04-22T19:14:19.727Z - Handled REQUEST_PROJECT_GRAPH. Handling time: 1467. Response time: 4.
[NX Daemon Server] - 2024-04-22T19:14:19.749Z - [REQUEST]: Responding to the client. handleHashTasks
[NX Daemon Server] - 2024-04-22T19:14:19.749Z - Done responding to the client handleHashTasks
[NX Daemon Server] - 2024-04-22T19:14:19.749Z - Handled HASH_TASKS. Handling time: 11. Response time: 0.
[NX Daemon Server] - 2024-04-22T19:14:19.749Z - Time taken for 'Load Nx Plugin: /home/paul/dev/jokedial/node_modules/.pnpm/nx@18.3.3_@swc-node+register@1.8.0_@swc+core@1.3.107/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json' 0.31881099939346313ms
[NX Daemon Server] - 2024-04-22T19:14:19.882Z - Established a connection. Number of open connections: 2
[NX Daemon Server] - 2024-04-22T19:14:19.883Z - Closed a connection. Number of open connections: 1
[NX Daemon Server] - 2024-04-22T19:14:19.883Z - Established a connection. Number of open connections: 2
[NX Daemon Server] - 2024-04-22T19:14:19.884Z - [REQUEST]: Client Request for Project Graph Received
[NX Daemon Server] - 2024-04-22T19:14:19.885Z - [REQUEST]: Responding to the client. project-graph
[NX Daemon Server] - 2024-04-22T19:14:19.886Z - Time taken for 'total for creating and serializing project graph' 0.4925150014460087ms
[NX Daemon Server] - 2024-04-22T19:14:19.887Z - Done responding to the client project-graph
[NX Daemon Server] - 2024-04-22T19:14:19.887Z - Handled REQUEST_PROJECT_GRAPH. Handling time: 1. Response time: 2.
[NX Daemon Server] - 2024-04-22T19:14:19.890Z - Established a connection. Number of open connections: 3
[NX Daemon Server] - 2024-04-22T19:14:20.008Z - Established a connection. Number of open connections: 4
[NX Daemon Server] - 2024-04-22T19:14:20.009Z - Closed a connection. Number of open connections: 3
[NX Daemon Server] - 2024-04-22T19:14:20.009Z - Established a connection. Number of open connections: 4
[NX Daemon Server] - 2024-04-22T19:14:20.010Z - [REQUEST]: Client Request for Project Graph Received
[NX Daemon Server] - 2024-04-22T19:14:20.011Z - [REQUEST]: Responding to the client. project-graph
[NX Daemon Server] - 2024-04-22T19:14:20.012Z - Time taken for 'total for creating and serializing project graph' 0.68766800314188ms
[NX Daemon Server] - 2024-04-22T19:14:20.013Z - Done responding to the client project-graph
[NX Daemon Server] - 2024-04-22T19:14:20.013Z - Handled REQUEST_PROJECT_GRAPH. Handling time: 1. Response time: 2.
[NX Daemon Server] - 2024-04-22T19:14:20.031Z - [REQUEST]: Responding to the client. handleHashTasks
[NX Daemon Server] - 2024-04-22T19:14:20.031Z - Done responding to the client handleHashTasks
[NX Daemon Server] - 2024-04-22T19:14:20.031Z - Handled HASH_TASKS. Handling time: 6. Response time: 0.
[NX Daemon Server] - 2024-04-22T19:14:20.031Z - Time taken for 'Load Nx Plugin: /home/paul/dev/jokedial/node_modules/.pnpm/nx@18.3.3_@swc-node+register@1.8.0_@swc+core@1.3.107/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json' 0.2610890008509159ms
[NX Daemon Server] - 2024-04-22T19:14:20.542Z - [WATCHER]: Processing file changes in outputs
[NX Daemon Server] - 2024-04-22T19:14:22.937Z - [REQUEST]: Responding to the client. recordOutputsHash
[NX Daemon Server] - 2024-04-22T19:14:22.937Z - Done responding to the client recordOutputsHash
[NX Daemon Server] - 2024-04-22T19:14:22.937Z - Handled RECORD_OUTPUTS_HASH. Handling time: 0. Response time: 0.
[NX Daemon Server] - 2024-04-22T19:14:22.950Z - Closed a connection. Number of open connections: 3
[NX Daemon Server] - 2024-04-22T19:14:22.954Z - [WATCHER]: Processing file changes in outputs
[NX Daemon Server] - 2024-04-22T19:14:23.654Z - [WATCHER]: 0 file(s) created or restored, 0 file(s) modified, 2 file(s) deleted
[NX Daemon Server] - 2024-04-22T19:14:23.655Z - [REQUEST]: Responding to the client. File watch changed
[NX Daemon Server] - 2024-04-22T19:14:23.655Z - Done responding to the client File watch changed
[NX Daemon Server] - 2024-04-22T19:14:23.655Z - Handled FILE-WATCH-CHANGED. Handling time: 0. Response time: 0.
[NX Daemon Server] - 2024-04-22T19:14:23.655Z - [WATCHER]: Processing file changes in outputs
[NX Daemon Server] - 2024-04-22T19:14:23.655Z - Time taken for 'changed-projects' 0.2585260011255741ms
[NX Daemon Server] - 2024-04-22T19:14:23.756Z - [REQUEST]: Updated workspace context based on watched changes, recomputing project graph...
[NX Daemon Server] - 2024-04-22T19:14:23.756Z - [REQUEST]: 
[NX Daemon Server] - 2024-04-22T19:14:23.756Z - [REQUEST]: apps/api/src/main.ts,apps/api/src/4913
[NX Daemon Server] - 2024-04-22T19:14:23.793Z - Established a connection. Number of open connections: 4
[NX Daemon Server] - 2024-04-22T19:14:23.794Z - Established a connection. Number of open connections: 5
[NX Daemon Server] - 2024-04-22T19:14:23.794Z - Time taken for 'Load Nx Plugin: /home/paul/dev/jokedial/node_modules/.pnpm/nx@18.3.3_@swc-node+register@1.8.0_@swc+core@1.3.107/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json' 0.24877099692821503ms
[NX Daemon Server] - 2024-04-22T19:14:23.794Z - [REQUEST]: Client Request for Project Graph Received
[NX Daemon Server] - 2024-04-22T19:14:23.794Z - [REQUEST]: Responding to the client. project-graph
[NX Daemon Server] - 2024-04-22T19:14:23.796Z - Time taken for 'total for creating and serializing project graph' 0.41770799830555916ms
[NX Daemon Server] - 2024-04-22T19:14:23.796Z - Closed a connection. Number of open connections: 4
[NX Daemon Server] - 2024-04-22T19:14:23.796Z - Done responding to the client project-graph
[NX Daemon Server] - 2024-04-22T19:14:23.797Z - Handled REQUEST_PROJECT_GRAPH. Handling time: 0. Response time: 3.
[NX Daemon Server] - 2024-04-22T19:14:23.819Z - [REQUEST]: Responding to the client. handleHashTasks
[NX Daemon Server] - 2024-04-22T19:14:23.819Z - Done responding to the client handleHashTasks
[NX Daemon Server] - 2024-04-22T19:14:23.819Z - Handled HASH_TASKS. Handling time: 10. Response time: 0.
[NX Daemon Server] - 2024-04-22T19:14:23.819Z - Time taken for 'Load Nx Plugin: /home/paul/dev/jokedial/node_modules/.pnpm/nx@18.3.3_@swc-node+register@1.8.0_@swc+core@1.3.107/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json' 0.2331859990954399ms
[NX Daemon Server] - 2024-04-22T19:14:24.318Z - [WATCHER]: Processing file changes in outputs
[NX Daemon Server] - 2024-04-22T19:14:26.577Z - [REQUEST]: Responding to the client. recordOutputsHash
[NX Daemon Server] - 2024-04-22T19:14:26.577Z - Done responding to the client recordOutputsHash
[NX Daemon Server] - 2024-04-22T19:14:26.577Z - Handled RECORD_OUTPUTS_HASH. Handling time: 0. Response time: 0.
[NX Daemon Server] - 2024-04-22T19:14:26.589Z - Closed a connection. Number of open connections: 3
[NX Daemon Server] - 2024-04-22T19:14:26.600Z - [WATCHER]: Processing file changes in outputs
[NX Daemon Server] - 2024-04-22T19:14:27.575Z - [WATCHER]: 0 file(s) created or restored, 0 file(s) modified, 2 file(s) deleted
[NX Daemon Server] - 2024-04-22T19:14:27.576Z - [WATCHER]: Processing file changes in outputs
[NX Daemon Server] - 2024-04-22T19:14:27.577Z - Time taken for 'changed-projects' 0.33142799884080887ms
[NX Daemon Server] - 2024-04-22T19:14:27.679Z - [REQUEST]: Updated workspace context based on watched changes, recomputing project graph...
[NX Daemon Server] - 2024-04-22T19:14:27.679Z - [REQUEST]: 
[NX Daemon Server] - 2024-04-22T19:14:27.679Z - [REQUEST]: apps/api/src/4913,apps/api/src/main.ts
[NX Daemon Server] - 2024-04-22T19:14:27.759Z - Time taken for 'Load Nx Plugin: /home/paul/dev/jokedial/node_modules/.pnpm/nx@18.3.3_@swc-node+register@1.8.0_@swc+core@1.3.107/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json' 1.7185580022633076ms
[NX Daemon Server] - 2024-04-22T19:14:30.088Z - Closed a connection. Number of open connections: 2
[NX Daemon Server] - 2024-04-22T19:14:30.091Z - Closed a connection. Number of open connections: 1
[NX Daemon Server] - 2024-04-22T19:14:30.096Z - Closed a connection. Number of open connections: 0

Package Manager Version

pnpm@8.15.2

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@poeck
Copy link
Author

poeck commented Apr 23, 2024

Seems like its not only an issue related to NestJS.

I've also tried it with an express app and a few different executors, but none of them worked for an express or nest app.

The only executor which works for me is next, but I obviously can't use that for a nest app.

@poeck poeck changed the title NestJS reload/refresh not working in v18 Reload/refresh not working in v18 Apr 23, 2024
@poeck
Copy link
Author

poeck commented Apr 23, 2024

Downgrading to v17 didn't work either.

@Nevation
Copy link

I also experienced this issue.
I wanted to use the latest version of NX, but I downgraded because of this issue.
This does not occur in 16.10.0, so I am using that version.

@poeck poeck changed the title Reload/refresh not working in v18 Reload/refresh not working in v18 and v17 Apr 25, 2024
@simonkoeck
Copy link

Got the same issue. Please fix ASAP. I can't/won't use NX any further if this major issue is not being fixed.

@Evanion
Copy link

Evanion commented Apr 28, 2024

I have experienced this with both Nest and Remix, on both windows and Mac.
It has a HUGE impact on my workflow, especially when I'm on windows where my customer requires me to sit on a slow windows laptop that they provide as I have to restart the process every time I want to check my code, and that takes 3 minutes.

@Coly010 Coly010 self-assigned this Apr 28, 2024
@poeck
Copy link
Author

poeck commented Apr 29, 2024

I have experienced this with both Nest and Remix, on both windows and Mac. It has a HUGE impact on my workflow, especially when I'm on windows where my customer requires me to sit on a slow windows laptop that they provide as I have to restart the process every time I want to check my code, and that takes 3 minutes.

I agree. Manually having to restart every process for each file change is so painful. I hope this gets fixed soon.

@AgentEnder AgentEnder added the scope: node Issues related to Node, Express, NestJS support for Nx label Apr 29, 2024
@Coly010
Copy link
Contributor

Coly010 commented May 7, 2024

I can't reproduce this on Windows or Mac with Nx 19.

Can you retry with Nx 19?

@Coly010 Coly010 added the blocked: retry with latest Retry with latest release or head. label May 7, 2024
@poeck
Copy link
Author

poeck commented May 8, 2024

I can't reproduce this on Windows or Mac with Nx 19.

Can you retry with Nx 19?

I just upgraded to v19, but the same error still exists. I'm on linux but as @Evanion mentioned, the issue seems to also exist windows and mac.

@poeck
Copy link
Author

poeck commented May 8, 2024

After spending hours debugging nx in my node_modules folders, I've identified the root cause of the issue! 🥳

The conflict arises when using nx alongside Vim, though it might also affect other editors. Here’s a brief explanation: Vim employs a delete-and-recreate method when saving files. This process involves deleting the file momentarily before writing a new one.

This behavior triggers the nx native file watcher (within the daemon) to emit a deleted event rather than an updated one. I suspect this causes nx to remove the file from its file graph (assuming that’s the correct terminology). Consequently, the project rebuilds after the initial deleted event, but subsequent modifications do not trigger any action, as nx considers the file permanently deleted and stops monitoring it.

For Vim users, a potential workaround is to use set nowritebackup. However, be cautious as this setting might lead to data loss in rare instances where the file fails to write successfully.

While I haven't tested it myself, ChatGPT suggests that other editors like IntelliJ, Eclipse, or Emacs may use a similar technique. Editors like Sublime offer this option, but it is not enabled by default.

I will keep this issue open as I believe an adjustment in nx’s file watcher could inherently support editors like Vim without requiring manual configuration changes.

@Evanion
Copy link

Evanion commented May 13, 2024

Personally, I'm exclusively on VSC. And I still gt this issue.

@poeck
Copy link
Author

poeck commented May 14, 2024

Personally, I'm exclusively on VSC. And I still gt this issue.

@Evanion I read there is a similar setting in vscode, which is not enabled by default. Maybe you could try clearing the cache, restarting the command and then saving the file with another editor?

Copy link

This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days.
It will be closed in 21 days if no results are provided.
If the issue is still present, please reply to keep it active.
If the issue was not present, please close this issue.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label May 22, 2024
@St1c
Copy link

St1c commented May 22, 2024

Is there any update to this issue. Still persists (NX 18.2.4 and Nestjs). In the same repo live reload of angular works just fine.

@poeck
Copy link
Author

poeck commented May 22, 2024

Is there any update to this issue. Still persists (NX 18.2.4 and Nestjs). In the same repo live reload of angular works just fine.

@St1c What editor are you using?

@github-actions github-actions bot removed the stale label May 23, 2024
Copy link

github-actions bot commented Jun 1, 2024

This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days.
It will be closed in 21 days if no results are provided.
If the issue is still present, please reply to keep it active.
If the issue was not present, please close this issue.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Jun 1, 2024
@poeck
Copy link
Author

poeck commented Jun 1, 2024

The same problem exists with the latest version of Nx.

@github-actions github-actions bot removed the stale label Jun 2, 2024
@Coly010
Copy link
Contributor

Coly010 commented Jun 7, 2024

Related: #21734

@stomvi
Copy link

stomvi commented Jul 18, 2024

Still having this issue with nx@19.5.1 and vscode@1.91 on macOS 14.4.1

Switching to esbuild as bundler solves this.

@paul-staskiewicz
Copy link

For me it was fixed by switching from the basic webpack configuration to the nx-enhanced configuration (https://nx.dev/recipes/webpack/webpack-config-setup#nxenhanced-configuration-with-composable-plugins).

@LinboLen
Copy link

use nxenhanced configuration works

{
  "name": "<project-name>",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/<project-name>/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "options": {
        "webpackConfig": "apps/<project-name>/webpack.config.js",
        "main": "apps/<project-name>/src/main.ts",
        "tsConfig": "apps/<project-name>/tsconfig.app.json",
        "optimization": false,
        "outputHashing": "none",
        "sourceMap": true,
        "outputPath": "dist/apps/<project-name>/",
        "compiler": "tsc",
        "target": "node"
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "<project-name>:build"
      },
      "configurations": {
        "development": {
          "buildTarget": "<project-name>:build:development"
        },
        "production": {
          "buildTarget": "<project-name>:build:production"
        }
      },
      "dependsOn": [
        {
          "projects": [
          ],
          "target": "build"
        }
      ]
    }
  }
}

and webpack.config.js

const { composePlugins, withNx } = require('@nx/webpack');

module.exports = composePlugins(
  // Default Nx composable plugin
  withNx(),
  // Custom composable plugin
  (config, { options, context }) => {
    // `config` is the Webpack configuration object
    // `options` is the options passed to the `@nx/webpack:webpack` executor
    // `context` is the context passed to the `@nx/webpack:webpack` executor
    // customize configuration here
    return config;
  }
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: node Issues related to Node, Express, NestJS support for Nx type: bug
Projects
None yet
Development

No branches or pull requests

10 participants