Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process.argv mismatching between 1.6.0 and 2.0.x #6203

Closed
6 tasks done
nazarhussain opened this issue Jul 23, 2024 · 5 comments · Fixed by #6213 or #6718
Closed
6 tasks done

process.argv mismatching between 1.6.0 and 2.0.x #6203

nazarhussain opened this issue Jul 23, 2024 · 5 comments · Fixed by #6213 or #6718
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@nazarhussain
Copy link

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.0 it's was undefined
  • With 2.0.x it 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.0 it's was []
  • With 2.0.x it 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

@sheremet-va
Copy link
Member

This probably happens because we want to statically replace testing-library's env vars:

'process.env.PTL_SKIP_AUTO_CLEANUP': !!process.env.PTL_SKIP_AUTO_CLEANUP,

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.

@nazarhussain
Copy link
Author

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?

@sheremet-va
Copy link
Member

sheremet-va commented Jul 23, 2024

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': '[]',
  }
})

@sheremet-va
Copy link
Member

Looks like the previous fix breaks config bundling (esbuild hangs) with headless: false

@sheremet-va sheremet-va reopened this Jul 24, 2024
@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) feat: browser Issues and PRs related to the browser runner and removed pending triage labels Jul 24, 2024
@nazarhussain
Copy link
Author

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': '[]',
  }
})

In my case I had to also add one other attribute to process.

{
          define: {
            "process.argv": "[]",
            "process.nextTick": "function noop(){}",
          },
}

@sheremet-va sheremet-va moved this to P2 - 5 in Team Board Jul 31, 2024
@sheremet-va sheremet-va moved this from P2 - 5 to Has plan in Team Board Aug 1, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
Archived in project
2 participants