Skip to content

Commit

Permalink
fix: improve error message upon using unsupported Vite version (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Feb 4, 2025
1 parent 13745b0 commit e7f407b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions vike/utils/isDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ export { isDevCheck }
export { applyDev }
export { applyPreview }

import { assert } from './assert.js'
import { version } from 'vite'
import { assertUsage } from './assert.js'
import type { ConfigEnv } from 'vite'

function isDevCheck(configEnv: ConfigEnv): boolean {
const { isPreview, command } = configEnv
// Released at vite@5.1.0 which is guaranteed with `assertVersion('Vite', version, '5.1.0')`
// - Release: https://github.com/vitejs/vite/blob/6f7466e6211027686f40ad7e4ce6ec8477414546/packages/vite/CHANGELOG.md#510-beta4-2024-01-26:~:text=fix(preview)%3A-,set%20isPreview%20true,-(%2315695)%20(93fce55
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/2135
assert(typeof isPreview === 'boolean', { isPreview, version })
// `assertVersion('Vite', version, '5.1.0')` isn't enough: https://github.com/vitejs/vite/pull/19355
assertUsage(
typeof isPreview === 'boolean',
'You are using an old Vite version; make sure to use Vite 5.1.0 or above.'
)
return command === 'serve' && !isPreview
}

Expand Down

0 comments on commit e7f407b

Please sign in to comment.