Vite-node is a tool that uses Vite as a Node.js runtime, enabling on-demand evaluation of JavaScript/TypeScript files with Vite's plugin pipeline, HMR, and alias resolution. Current stable version is v6.0.0, which requires Node ^20.19.0 || >=22.12.0 and upgrades Vite to v8. The project was originally extracted from Nuxt 3's SSR and previously powered Vitest, but Vitest has migrated to Vite's built-in Environment Module Runner. vite-node remains maintained for legacy ecosystem support, but new projects should consider using Vite's native solution. It features top-level await, shims for __dirname/__filename in ESM, and native Node module access. The library is published as a standalone package on npm and follows a semver release cadence with breaking changes in major versions.
npm install vite-nodeVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up vite-node programmatically: create Vite server, configure ViteNodeServer and ViteNodeRunner, install source map support, and execute a TypeScript file.
Ensure your Vite plugins are compatible with Vite v8. Update if necessary.
Use ESM imports. If you were using CommonJS require(), switch to import or update your Node.js to support ESM.
For new projects, consider using Vite's environment API directly: https://vite.dev/guide/api-environment.html
Always import from 'vite-node/client' or 'vite-node/server' as appropriate.
Check Vite version and conditionally call buildStart if major version is less than 6.
Use ESM import: import { ViteNodeRunner } from 'vite-node/client'; or set "type": "module" in package.json.Use named exports from subpaths: import { ViteNodeServer } from 'vite-node/server'.Upgrade to vite-node v5+ or check that you are using the correct export name.
Ensure the module is installed and configured in Vite's resolve.alias or optimizeDeps.