Skip to content

Commit a1be1bf

Browse files
Copilotsapphi-red
andauthored
feat(cli): add Node.js version warning for unsupported versions (#20638)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sapphi-red <[email protected]>
1 parent 1559577 commit a1be1bf

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { checkNodeVersion } from '../cli'
3+
4+
describe('CLI Node.js version checking', () => {
5+
test.each([
6+
// Unsupported versions
7+
['18.20.0', false],
8+
['20.18.5', false],
9+
['22.11.0', false],
10+
// Supported versions
11+
['20.19.0', true],
12+
['20.20.1', true],
13+
['22.12.0', true],
14+
['22.13.1', true],
15+
['23.0.0', true],
16+
])('should return %1 for Node.js version %0', (version, expected) => {
17+
const result = checkNodeVersion(version)
18+
expect(result).toBe(expected)
19+
})
20+
})

packages/vite/src/node/cli.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,26 @@ import type { LogLevel } from './logger'
1111
import { createLogger } from './logger'
1212
import type { InlineConfig } from './config'
1313

14+
export function checkNodeVersion(nodeVersion: string): boolean {
15+
const currentVersion = nodeVersion.split('.')
16+
const major = parseInt(currentVersion[0], 10)
17+
const minor = parseInt(currentVersion[1], 10)
18+
const isSupported =
19+
(major === 20 && minor >= 19) || (major === 22 && minor >= 12) || major > 22
20+
return isSupported
21+
}
22+
23+
if (!checkNodeVersion(process.versions.node)) {
24+
// eslint-disable-next-line no-console
25+
console.warn(
26+
colors.yellow(
27+
`You are using Node.js ${process.versions.node}. ` +
28+
`Vite requires Node.js version 20.19+ or 22.12+. ` +
29+
`Please upgrade your Node.js version.`,
30+
),
31+
)
32+
}
33+
1434
const cli = cac('vite')
1535

1636
// global options

0 commit comments

Comments
 (0)