Skip to content

Vite preview --watch does not work anymore #31604

@nkalinov

Description

@nkalinov

Current Behavior

Since v21 Vite preview mode with --watch argument doesn't work anymore. This used to rebuild the project automatically on file change.
Related PR - #14412

Same happens with "useInferencePlugins": false

Also tried adding "watch": true to the buildTarget explicitly but it hangs the preview task as the build task does not end. (though this case is the same as in v20, hence why I've always passed it on the CLI).

npx nx preview mfe1 --watch

> nx run @test-workspace-nx-21.2.0/mfe1:build  [existing outputs match the cache, left as is]


> nx run @test-workspace-nx-21.2.0/mfe1:preview

> vite preview --watch

file:///Users/nikola.kalinov/dev/test-workspace-nx-21.2.0/node_modules/vite/dist/node/cli.js:448
          throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
                ^

CACError: Unknown option `--watch`
    at Command.checkUnknownOptions (file:///Users/nikola.kalinov/dev/test-workspace-nx-21.2.0/node_modules/vite/dist/node/cli.js:448:17)
    at CAC.runMatchedCommand (file:///Users/nikola.kalinov/dev/test-workspace-nx-21.2.0/node_modules/vite/dist/node/cli.js:646:13)
    at CAC.parse (file:///Users/nikola.kalinov/dev/test-workspace-nx-21.2.0/node_modules/vite/dist/node/cli.js:585:12)
    at file:///Users/nikola.kalinov/dev/test-workspace-nx-21.2.0/node_modules/vite/dist/node/cli.js:947:5
    at ModuleJob.run (node:internal/modules/esm/module_job:274:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:644:26)

Expected Behavior

npx nx preview <name> --watch should build+watch the project and start preview server.

GitHub Repo

No response

Steps to Reproduce

  1. npx nx g app apps/mfe1
  2. npx nx preview mfe1 --watch

Nx Report

Node           : 23.10.0
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.9.2

nx                     : 21.2.0
@nx/js                 : 21.2.0
@nx/eslint             : 21.2.0
@nx/workspace          : 21.2.0
@nx/devkit             : 21.2.0
@nx/eslint-plugin      : 21.2.0
@nx/module-federation  : 21.2.0
@nx/react              : 21.2.0
@nx/vite               : 21.2.0
@nx/web                : 21.2.0
typescript             : 5.8.3
---------------------------------------
Registered Plugins:
@nx/js/typescript
@nx/react/router-plugin
@nx/eslint/plugin
@nx/vite/plugin
---------------------------------------
Cache Usage: 247.00 KB / 46.04 GB

Failure Logs

Package Manager Version

No response

Operating System

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

Additional Information

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions