vitest
vitest copied to clipboard
`process.argv` mismatching between `1.6.0` and `2.0.x`
Describe the bug
The default value for process.argv does not match between above mentioned versions, when run with the browsers mode.
- With
1.6.0it's was undefined - With
2.0.xit is an array with few values
If we use vite-plugin-node-polyfills to pollyfil the process it had different weird behavior.
- With
1.6.0it's was[] - With
2.0.xit is undefined
The vite-plugin-node-polyfills version is same in both cases, so the shims does not change at all.
Reproduction
https://stackblitz.com/edit/vitest-2-env-argv https://stackblitz.com/edit/vitest-1-env-argv
System Info
System:
OS: macOS 14.5
CPU: (11) arm64 Apple M3 Pro
Memory: 200.19 MB / 18.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.4.0 - ~/.asdf/installs/nodejs/22.4.0/bin/node
Yarn: 1.22.22 - ~/.asdf/installs/nodejs/22.4.0/bin/yarn
npm: 10.8.1 - ~/.asdf/plugins/nodejs/shims/npm
Browsers:
Brave Browser: 126.1.67.134
Safari: 17.5
Used Package Manager
yarn
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
This probably happens because we want to statically replace testing-library's env vars:
https://github.com/vitest-dev/vitest/blob/883f3482745772ccf24087246f4f7af7414ae233/packages/browser/src/node/plugin.ts#L339
But looks like adding process.* creates an empty process object globally:
https://github.com/vitejs/vite/blob/b240a8347e7b62bee9d2212625732bb0d8c78633/packages/vite/src/client/env.ts#L17
Not sure how to fix this yet.
In our project a deep dependency is looking for process.argv and that is causing to fail the upgrade to vitest 2.0.x.
Until it's fixed, is there a workaround you could think of?
Until it's fixed, is there a workaround you could think of?
I don't think this can be fixed soon on Vite side, but you can define process.argv in defines:
export default defineConfig({
defines: {
'process.argv': '[]',
}
})
Looks like the previous fix breaks config bundling (esbuild hangs) with headless: false
Until it's fixed, is there a workaround you could think of?
I don't think this can be fixed soon on Vite side, but you can define
process.argvindefines:export default defineConfig({ defines: { 'process.argv': '[]', } })
In my case I had to also add one other attribute to process.
{
define: {
"process.argv": "[]",
"process.nextTick": "function noop(){}",
},
}