You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using Vitest in a Yarn PnP and monorepo environment, and I’ve encountered an intermittent issue when using the Vitest VSCode extension.
The issue occurs when the extension load the Vitest process: it usually loads successfully right after I open the project in VSCode, but if I hit the ‘Refresh’ button to reload Vitest, the process often fails. I have also noticed occasional failures even on the initial load. I’ve attached the error log at the bottom of this report.
After debugging the error logs and the extension’s source code, I found that during the first successful load, Vitest is executed with the parameters --require /Users/choejun-yeong/3o3/3o3_service/.pnp.cjs --experimental-loader file:///Users/choejun-yeong/3o3/3o3_service/.pnp.loader.mjs, as you can see in below error log. However, on the second attempt, these parameters are missing.
I traced this behavior back to this part of the source code:
Where the function resolveVitestPackagePath tries to require.resolve('vitest/package.json'). If that fails, it falls back to a Yarn PnP-specific resolution.
The problem occurs specifically with the require.resolve('vitest/package.json'). When the Vitest load succeeds, this code throws an error(Cannot find module ...), but when the load fails, the require.resolve call succeeds and returns a path like /Users/choejun-yeong/3o3/3o3_service/.yarn/__virtual__/vitest-virtual-d765642456/0/cache/vitest-npm-2.1.2-6430425a96-3a331a1049.zip/node_modules/vitest/package.json.
Although I haven’t been able to consistently reproduce the issue, I’ve observed that require.resolve throws when the project is freshly opened in VSCode (which leads to Vitest loading successfully). However, after some time has passed, require.resolve succeeds (leading to the Vitest load failure).
When I removed the require.resolve call from above code, the Vitest process always loaded successfully.
Based on this, could you help me understand what might be causing this issue? My suspicion is that determining whether Yarn PnP is being used based on require.resolve alone may not be reliable.
Thank you!
Reproduction
I attempted to create a reproduction repository but was unsuccessful. The repository where this issue occurs is private, so unfortunately, I can’t share it at this time.
Output
[INFO 오후 5:12:25] [v1.6.0] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 오후 5:12:26] [API] Running Vitest vpnp (3o3_service/vitest.workspace.ts) with [email protected]: /Users/choejun-yeong/.nvm/versions/node/v20.16.0/bin/node --require /Users/choejun-yeong/3o3/3o3_service/.pnp.cjs --experimental-loader file:///Users/choejun-yeong/3o3/3o3_service/.pnp.loader.mjs
[INFO 오후 5:12:26] [API] Vitest vpnp (3o3_service/vitest.workspace.ts) child process 47661 created
[INFO 오후 5:12:26] [VSCODE] Watching 3o3_service with pattern **/*
[INFO 오후 5:12:36] [API] Vitest process 47661 closed successfully
[INFO 오후 5:12:36] [API] Running Vitest v2.1.2 (3o3_service/vitest.workspace.ts) with [email protected]: /Users/choejun-yeong/.nvm/versions/node/v20.16.0/bin/node
[Error 오후 5:12:36] [API] Failed to refresh Vitest [Error Error] Vitest failed to start:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/choejun-yeong/3o3/3o3_service/.yarn/__virtual__/vitest-virtual-d765642456/0/cache/vitest-npm-2.1.2-6430425a96-3a331a1049.zip/node_modules/vitest/dist/node.js' imported from /Users/choejun-yeong/.vscode/extensions/vitest.explorer-1.6.0/dist/worker.js
at finalizeResolution (node:internal/modules/esm/resolve:265:11)
at moduleResolve (node:internal/modules/esm/resolve:933:10)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
at defaultImportModuleDynamically (node:internal/modules/esm/utils:194:31)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:216:12)
at To (/Users/choejun-yeong/.vscode/extensions/vitest.explorer-1.6.0/dist/worker.js:20:7180)
Error: Vitest failed to start:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/choejun-yeong/3o3/3o3_service/.yarn/__virtual__/vitest-virtual-d765642456/0/cache/vitest-npm-2.1.2-6430425a96-3a331a1049.zip/node_modules/vitest/dist/node.js' imported from /Users/choejun-yeong/.vscode/extensions/vitest.explorer-1.6.0/dist/worker.js
at finalizeResolution (node:internal/modules/esm/resolve:265:11)
at moduleResolve (node:internal/modules/esm/resolve:933:10)
at defaultResolve (node:internal/modules/esm/resolve:1169:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:383:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:352:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:227:38)
at ModuleLoader.import (node:internal/modules/esm/loader:315:34)
at defaultImportModuleDynamically (node:internal/modules/esm/utils:194:31)
at importModuleDynamicallyCallback (node:internal/modules/esm/utils:216:12)
at To (/Users/choejun-yeong/.vscode/extensions/vitest.explorer-1.6.0/dist/worker.js:20:7180)
at ChildProcess.p (/Users/choejun-yeong/.vscode/extensions/vitest.explorer-1.6.0/dist/extension.js:19:3538)
at ChildProcess.emit (node:events:519:28)
at ChildProcess.emit (node:domain:488:12)
at emit (node:internal/child_process:951:14)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Version
1.6.0
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.
Describe the bug
TL:DR;
This part of the extension source code seems to make Vitest fail to load on Yarn PnP. It works if I remove L19-L25
Hello,
I’m using Vitest in a Yarn PnP and monorepo environment, and I’ve encountered an intermittent issue when using the Vitest VSCode extension.
The issue occurs when the extension load the Vitest process: it usually loads successfully right after I open the project in VSCode, but if I hit the ‘Refresh’ button to reload Vitest, the process often fails. I have also noticed occasional failures even on the initial load. I’ve attached the error log at the bottom of this report.
After debugging the error logs and the extension’s source code, I found that during the first successful load, Vitest is executed with the parameters
--require /Users/choejun-yeong/3o3/3o3_service/.pnp.cjs --experimental-loader file:///Users/choejun-yeong/3o3/3o3_service/.pnp.loader.mjs
, as you can see in below error log. However, on the second attempt, these parameters are missing.I traced this behavior back to this part of the source code:
vscode/src/api/resolve.ts
Lines 18 to 38 in becf826
Where the function
resolveVitestPackagePath
tries torequire.resolve('vitest/package.json')
. If that fails, it falls back to a Yarn PnP-specific resolution.The problem occurs specifically with the
require.resolve('vitest/package.json')
. When the Vitest load succeeds, this code throws an error(Cannot find module ...
), but when the load fails, therequire.resolve
call succeeds and returns a path like /Users/choejun-yeong/3o3/3o3_service/.yarn/__virtual__/vitest-virtual-d765642456/0/cache/vitest-npm-2.1.2-6430425a96-3a331a1049.zip/node_modules/vitest/package.json
.Although I haven’t been able to consistently reproduce the issue, I’ve observed that
require.resolve
throws when the project is freshly opened in VSCode (which leads to Vitest loading successfully). However, after some time has passed,require.resolve
succeeds (leading to the Vitest load failure).When I removed the
require.resolve
call from above code, the Vitest process always loaded successfully.Based on this, could you help me understand what might be causing this issue? My suspicion is that determining whether Yarn PnP is being used based on
require.resolve
alone may not be reliable.Thank you!
Reproduction
I attempted to create a reproduction repository but was unsuccessful. The repository where this issue occurs is private, so unfortunately, I can’t share it at this time.
Output
Version
1.6.0
Validations
The text was updated successfully, but these errors were encountered: