Migrating from @nx/vite to @nx/vitest
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
Generators
@nx/vite:vitest→@nx/vitest:configuration
Executors
@nx/vite:test→@nx/vitest:test
Plugins
@nx/vite/plugin(for vitest) →@nx/vitest
Migration steps
1. Install @nx/vitest
npm install --save-dev @nx/vitest
# or
pnpm add -D @nx/vitest
# or
yarn add -D @nx/vitest
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)
Before:
{
"plugins": [
{
"plugin": "@nx/vite/plugin",
"options": {
"testTargetName": "test"
}
}
]
}
After:
{
"plugins": [
{
"plugin": "@nx/vitest",
"options": {
"testTargetName": "test"
}
}
]
}
4. Update future generator usage
When adding vitest to new projects:
# Old
nx g @nx/vite:vitest my-project
# New
nx g @nx/vitest:configuration my-project
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
- vite.config.ts / vitest.config.ts: No changes needed
- Test files: No changes needed
- vitest.config.ts: No changes needed
Questions?
File an issue at https://github.com/nrwl/nx/issues