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

vitest --ui errors when run from PowerShell/cmd #1870

Closed
6 tasks done
alextompkins opened this issue Aug 17, 2022 · 9 comments
Closed
6 tasks done

vitest --ui errors when run from PowerShell/cmd #1870

alextompkins opened this issue Aug 17, 2022 · 9 comments

Comments

@alextompkins
Copy link

Describe the bug

@vitest/ui seems unable to handle Windows absolute file paths. When running from PowerShell or cmd, we get the following error:

> vitest --ui

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: spawn undefined\System32\WindowsPowerShell\v1.0\powershell ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
  path: 'undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBoAHQAdABwADoALwAvADEAMgA3AC4AMAAuADAALgAxADoANQAxADIAMAA0AC8AXwBfAHYAaQB0AGUAcwB0AF8AXwAvACIA'
  ]
}

The problem does not occur when running the command via Git Bash, which uses synthesized unix-style file paths. As you can see from the stacktrace, it is trying to access a path with the drive letter of undefined.

Reproduction

Any repo using:

  • "vite": ^3.0.4
  • "vitest": "^0.22.0"
  • "@vitest/ui": "^0.22.0"

and running on Windows.

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 8.55 GB / 31.73 GB
  Binaries:
    Node: 16.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.5.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (104.0.1293.54)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @vitejs/plugin-react: ^2.0.0 => 2.0.0
    vite: ^3.0.4 => 3.0.8
    vitest: ^0.22.0 => 0.22.0

Used Package Manager

npm

Validations

@antfu
Copy link
Member

antfu commented Aug 29, 2022

We temporarily close this due to the lack of enough information.
Please provide a minimal reproduction to reopen the issue.
Thanks.

Why reproduction is required

@antfu antfu closed this as completed Aug 29, 2022
@alextompkins
Copy link
Author

Hi @antfu, the issue occurs with any repo which uses vitest, if you run the vitest --ui command from PowerShell or cmd. There is no way (that I know of) I can provide a reproducible example which includes either of those, except maybe a Windows docker container (but you'd need Windows to run that anyway!).

@rodamaral
Copy link

I had a similar issue.

It turns out my shell had an environment variable called BROWSER with an outdated value. Vitest uses this variable (if defined) to open the browser, so using an invalid value will attempt to call an invalid command. The solution was to erase this variable (in my case, from bash).

It's also possible to do something like "test-ui": "BROWSER=your-browser-name vitest --ui" in your package.json for testing purposes.

@alextompkins
Copy link
Author

alextompkins commented Jan 3, 2023

@rodamaral interesting, although I'm fairly sure that's not the same issue. As you can see from the stacktrace, it seems like the issue stems from the drive letter in the path being undefined. I will check however that there isn't any BROWSER variable defined in the shell.

It's worth noting that I do not get this issue in bash, only cmd and PowerShell.

@olemarius
Copy link

I have the same issue in Windows 11:

"vite": "^4.1.4",
"vitest": "^0.29.2",
"@vitest/ui": "^0.29.2",

Also made sure that I added %SystemRoot%\System32\WindowsPowerShell\v1.0\ to Path in Environment variables.

I'm using Volta to manage node etc: https://volta.sh/

 DEV  v0.29.2 C:/Git/BlocPlatform/Bloc/Frontend/Bloc.Vue
      UI started at http://localhost:51204/__vitest__/

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: spawn undefined\System32\WindowsPowerShell\v1.0\powershell ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
  path: 'undefined\\System32\\WindowsPowerShell\\v1.0\\powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBoAHQAdABwAHMAOgAvAC8AbABvAGMAYQBsAGgAbwBzAHQAOgA1ADEAMgAwADQALwBfAF8AdgBpAHQAZQBzAHQAXwBfAC8AIgA='
  ]
}

Node.js v18.15.0

 *  The terminal process "C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe -Command npm run vitest" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

@StrikeAgainst
Copy link

StrikeAgainst commented Apr 9, 2023

Do you use loadEnv to include your own environment variables? If so, do you add them like this?

process.env = {...process.env, ...loadEnv(mode, process.cwd())};

The issue is that under the hood Vite seems to read the variable process.env.SYSTEMROOT, which is actually defined as process.env.SystemRoot (at least on Windows machines). While process.env doesn't seem to be case sensitive with its properties, it seems they WILL get case sensitive if you de- and restructure the object like above, making process.env.SYSTEMROOT undefined.

Instead of de-/restructuring, do an object assignment instead:

Object.assign(process.env, loadEnv(mode, process.cwd()))

Hope this might help anyone.

EDIT: I should add that this issue seems to regard Vite in general. I'm not sure how this translates to vitest, but I figure the issue might be similar.

@zerg41
Copy link

zerg41 commented Jul 29, 2023

Do you use loadEnv to include your own environment variables? If so, do you add them like this?

process.env = {...process.env, ...loadEnv(mode, process.cwd())};

The issue is that under the hood Vite seems to read the variable process.env.SYSTEMROOT, which is actually defined as process.env.SystemRoot (at least on Windows machines). While process.env doesn't seem to be case sensitive with its properties, it seems they WILL get case sensitive if you de- and restructure the object like above, making process.env.SYSTEMROOT undefined.

Instead of de-/restructuring, do an object assignment instead:

Object.assign(process.env, loadEnv(mode, process.cwd()))

Hope this might help anyone.

EDIT: I should add that this issue seems to regard Vite in general. I'm not sure how this translates to vitest, but I figure the issue might be similar.

Thank you man!
It really helps)

@sheremet-va
Copy link
Member

Cannot reproduce the error described in the issue on Windows 11. Both cmd and powershell work fine.

@github-actions
Copy link

Hello @alextompkins. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants