vscode: Vitest failes to start in vscode >=1.90 when using Yarn PnP
Describe the bug
With latest VSCode (version 1.90.2) the extension fails to start Vitest in a project setup with Yarn PnP:
Downgrading VSCode to version 1.89.1 results in Vitest process being successfully created:
I suspect it has to do with Electron upgrade in latest VSCode release that comes bundled with Node.js 20.
Reproduction
https://github.com/Nithanim-Work/vitest-reproducer (reusing minimal example from https://github.com/vitest-dev/vscode/issues/416)
Output
[INFO 21:10:03] [v0.12.4] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 21:10:04] [API] Running Vitest vpnp (web/vitest.config.ts) with Node.js: /Users/fima/.asdf/shims/node
[Error 21:10:05] [Error Error] Vitest failed to start:
y
Error: Vitest failed to start:
y
at ChildProcess.f (/Users/fima/.vscode/extensions/vitest.explorer-0.12.4/dist/extension.js:18:5392)
at ChildProcess.emit (node:events:514:28)
at emit (node:internal/child_process:951:14)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Version
0.12.4
Validations
- Check that you are using the latest version of the extension
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 21 (4 by maintainers)
Commits related to this issue
- fix: fully support yarn pnp Closes #426 — committed to sheremet-va/vitest-vscode by sheremet-va 2 years ago
- fix: fully support yarn pnp (#475) Closes #426 — committed to vitest-dev/vscode by sheremet-va 2 years ago
After messing around for a while, I managed to figure out a workaround. The pnp loader doesn’t seem to want to resolve modules the way the worker hopes to be able to (i.e. it doesn’t seem to check the workspace at all unless the importer or the imported script are in the workspace). Not really sure if this is an issue with yarn or if the extension is meant to be doing something different (like using the plugin API or something)
Unpacking vitest and pointing directly to it fixes the
vitest/nodeimport as @viell-dev says above, but the extension seems to skip adding the pnp hooks when you specifyvitestPackagePath,so vitest’s dependencies would also fail to resolve. This can be worked around through theNODE_OPTIONSenvironment variable; though the extension could be updated to skip this requirementyarn unplug vitest(don’t think -R is needed)vitest.vitestPackagePathto point to the unpackedpackage.json(this may be different for you)vitest.nodeEnvto set theNODE_OPTIONSenv. var similar to the following:i imagine there’s a way to configure this so that you don’t have to hard-set the paths but this works for me
@TehPers please, check if v1.2.11 fixes it for you.
I’m also able to repro (Yarn PNP with workspaces) and have tried installing the extension globally, no luck.
You can get past this error and have extension make it past startup by installing whatever package it says is missing in the directory its looking for it… but you’ll then run into issues when you try to run any test via the UI as each test’s packages are going to be missing.
Node.js: v20.17.0 (with
corepack enable) VSCode: v1.93.1yarn create viteto make a project. (yarn@3.5.0is installed, as isvite@5.4.1) - all default settingsyarn dlx @yarnpkg/sdks vscodeto setup editor SDKsyarn add -D vitest(installsvitest@2.1.1)src/example.test.tswith a very simple unit test. Verify it runs withyarn run vitest.Edit: adding a
vite.config.tsdoesn’t fix the error either.I may be missing something, but I’m unfortunately still getting a startup crash with Yarn PnP on v1.2.10: