Skip to content

[Bug]: Unable to debug in pnpm workspace with shared/root jestΒ #447

@dougludlow

Description

@dougludlow

πŸ“ Description

Running tests from the code lens works just fine with enableESM set to true. The problem we're running into is when we try to debug tests from code lens it's attempting to access jest from the project's node_modules, but jest is installed in the workspace root, so it cannot be found.


πŸ–₯️ Environment

Item Value
Operating System macOS 26.2
Shell zsh
Project Framework Nx, NestJS
Test Framework Jest
Jest/Vitest Config Name jest.config.ts
Project Type Monorepo
IDE VSCode
VSCode Version 1.108.2
Extension Version 0.4.111
Last Working Version They've changed a bunch recently, hard to tell

πŸ”§ Debug Logging

N/A

πŸ“ Project Structure

β”œβ”€β”€ node_modules
β”œβ”€β”€ package.json
β”œβ”€β”€ jest.config.js (generated by nx)
β”œβ”€β”€ packages/
β”‚   └── my-project/
β”‚       └── node_modules
β”‚       └── package.json (contains workspace references)
β”‚       └── jest.config.ts
β”‚       └── my-thing.ts
β”‚       └── my-thing.spec.ts

βš™οΈ Jest/Vitest Configuration

N/A

πŸ› οΈ Extension Settings

	"jestrunner.enableESM": true

πŸ”„ Steps to Reproduce

Please provide detailed steps to reproduce the issue:

  1. Open test file
  2. Click "Debug" code lens option

βœ… Expected Behavior

Able to debug test. Should use jest installed in the root node_modules.


❌ Actual Behavior

An error instead


πŸ“‹ Test Command Output

Console/Terminal Output:

cd /Users/me/Source/my-workspace/packages/my-project ; 
/usr/bin/env \
  'NODE_OPTIONS= --require "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.js"  --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS=:::{"inspectorIpc":"/var/folders/tn/ygcv2bxj0h1fn6z77fs977t80000gp/T/node-cdp.72583-b87cb9d7-81.sock","deferredMode":false,"waitForDebugger":"","execPath":"/opt/homebrew/opt/nvm/versions/node/v22.11.0/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/var/folders/tn/ygcv2bxj0h1fn6z77fs977t80000gp/T/node-debug-callback-d9073989cec9bbe8"}' \
  /opt/homebrew/opt/nvm/versions/node/v22.11.0/bin/node \
  --experimental-vm-modules \
  ./node_modules/jest/bin/jest.js \
  --runInBand \
  /Users/me/Source/my-workspace/packages/my-project/my-thing\\.spec\\.ts \
  -c \
  /Users/me/Source/my-workspace/packages/my-project/jest.config.ts \
  -t \
  MyThing\ should\ do\ the\ thing
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/modules/cjs/loader:1252
  throw err;
  ^

Error: Cannot find module '/Users/me/Source/my-workspace/packages/my-project/node_modules/jest/bin/jest.js'
    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
    at Function._load (node:internal/modules/cjs/loader:1075:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:170:5)
    at node:internal/main/run_main_module:36:49 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v22.11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions