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”The old @nx/vite:vitest generator and @nx/vite:test executor still work but are deprecated. They will be removed in Nx 23. Please migrate before upgrading to Nx 23.
When you use the deprecated generators/executors, you'll see a warning message:
The '@nx/vite:vitest' generator is deprecated. Please use '@nx/vitest:configuration' instead.This generator will be removed in Nx 23.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