Description
Description
I have tried the settings.json in #19595 and #19110.
It just doesn't work for me, the breakponits in vite.config.ts
just can't hit.
This only works for me if I also set a breakpoint to .\node_modules\vite\dist\node\chunks\dep-DBxKXgDP.js#L49224
:
const config = await (typeof configExport === "function" ? configExport(configEnv) : configExport);
which is in source code:
vite/packages/vite/src/node/config.ts
Lines 1836 to 1838 in 494f854
Then a step over/continue
will call the function and hit the breakpoint in vite.config.ts
.
Alternatively, use "type":"commonjs"
in package.json
works even without these labour, but I don't want that.
Reproduction
https://github.com/RabbitSeries/debugTest
1.create-vite
npm create vite
Project name: debugTest
Package name: debugtest
Select React->TypeScript
cd debugTest
npm i
code .
2.Change vite.config.ts to export a function:
import { type ConfigEnv, defineConfig, type UserConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig((env: ConfigEnv) => {
if (env.command === 'serve') {
const devConfig: UserConfig = {
plugins: [react()],
server: {
port: 9262
},
preview: {
port: 9262
}
}
return devConfig
} else {
const buildConfig: UserConfig = {
plugins: [react()],
build: {
outDir: "dist"
}
}
return buildConfig
}
})
3.Add the ./.vscode/settings.json as in Doc
4.Set the breakpoint at the if
statement inside the vite.config.ts
5.Hit the debug at the code lens of package.json, select dev
6.Breakpoint doesn't hit
SystemInfo
C:\Users\rabbit\debugTest>npx envinfo --system --npmPackages '{vite,@vitejs/*,rollup}' --binaries --browsers
Need to install the following packages:
envinfo@7.14.0
Ok to proceed? (y) y
System:
OS: Windows 11 10.0.26100
CPU: (8) x64 Intel(R) Core(TM) i5-10300H CPU @ 2.50GHz
Memory: 9.75 GB / 15.91 GB
Binaries:
Node: 22.12.0 - D:\Program Files\nodejs\node.EXE
npm: 10.9.0 - D:\Program Files\nodejs\npm.CMD
pnpm: 10.11.1 - ~\AppData\Local\pnpm\pnpm.EXE
Browsers:
Edge: Chromium (131.0.2903.70)
Used Package Manager
npm
Logs
I think not relevant.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.