Migrating from @nx/vite to @nx/vitest
Section titled “Migrating from @nx/vite to @nx/vitest”Overview
Section titled “Overview”Vitest functionality has been split from @nx/vite into a standalone @nx/vitest package. This provides better separation of concerns and allows vitest to be used independently of vite.
What changed
Section titled “What changed”Generators
Section titled “Generators”@nx/vite:vitest→@nx/vitest:configuration
Executors
Section titled “Executors”@nx/vite:test→@nx/vitest:test
Plugins
Section titled “Plugins”@nx/vite/plugin(for vitest) →@nx/vitest
Migration steps
Section titled “Migration steps”1. Install @nx/vitest
Section titled “1. Install @nx/vitest”npm install --save-dev @nx/vitest# orpnpm add -D @nx/vitest# oryarn add -D @nx/vitest2. Update project.json
Section titled “2. Update project.json”Before:
{ "targets": { "test": { "executor": "@nx/vite:test", "options": { "config": "vite.config.ts" } } }}After:
{ "targets": { "test": { "executor": "@nx/vitest:test", "options": { "config": "vite.config.ts" } } }}3. Update nx.json (if using plugin)
Section titled “3. Update nx.json (if using plugin)”Before:
{ "plugins": [ { "plugin": "@nx/vite/plugin", "options": { "testTargetName": "test" } } ]}After:
{ "plugins": [ { "plugin": "@nx/vitest", "options": { "testTargetName": "test" } } ]}4. Update future generator usage
Section titled “4. Update future generator usage”When adding vitest to new projects:
# Oldnx g @nx/vite:vitest my-project
# Newnx g @nx/vitest:configuration my-projectBackward compatibility
Section titled “Backward compatibility”Nx 23 removed all vitest support from @nx/vite. The @nx/vite:test executor, the @nx/vite:vitest generator, and vitest target inference in @nx/vite/plugin no longer exist in v23. Everything is now provided exclusively by @nx/vitest.
If you are upgrading to Nx 23, the ensure-vitest-package-migration migration runs automatically via nx migrate and handles the conversion for you:
- Installs
@nx/vitestwhen vitest usage is detected in the workspace. - Swaps every
@nx/vite:testreference (project targets andtargetDefaults) to@nx/vitest:test. - Splits vitest options out of
@nx/vite/pluginregistrations into dedicated@nx/vitestplugin entries. - Adds an
@nx/vitestplugin entry alongside any default-config@nx/vite/pluginregistration.
See the migration reference for full details on what the automated migration does. For manual steps, follow the guide above.
No changes required for these files
Section titled “No changes required for these files”- vite.config.ts / vitest.config.ts: No changes needed
- Test files: No changes needed
- vitest.config.ts: No changes needed
Questions?
Section titled “Questions?”File an issue at https://github.com/nrwl/nx/issues