vitest-dev / vscode

VS Code extension for Vitest
https://vitest.dev/vscode
MIT License
740 stars 83 forks source link

Crashes with "Cannot find module" #448

Open Sti2nd opened 1 month ago

Sti2nd commented 1 month ago

Describe the bug

See the below Output and Reproduction.

Perhaps something weird; I have specified vitest version 2.0.5 in package.json and running with CLI works. Still the extension prints out vitest version 1.5.1.

Reproduction

Closed source code, but here are the relevant files (slightly modified)

// The file called findEnv.test.ts
/* eslint-disable no-template-curly-in-string */
import { env } from 'process';
import { findEnv } from './findEnv.js';

const CLIENTID = 'prefix/app/${APP_VERSION}';

describe('config', () => {
  it('should find env', () => {
    env.APP_VERSION = '1.0.0';

    const result = findEnv(CLIENTID);
    expect(result).toBe('prefix/app/1.0.0');
  });

  it('should throw error', () => {
    delete env.APP_VERSION;

    expect(() => findEnv(CLIENTID)).toThrowError(
      /Could not find env APP_VERSION/,
    );
  });
});
// The file called findEnv.ts
import { env } from 'process';

export function findEnv(str: string, strict: boolean = true): string {
  // Simplified code
  if (str === 'prefix/app/1.0.0') {
    return str
  } else {
    throw new Error(`Could not find env APP_VERSION`);
  }
}

Output

[INFO 2:17:42 PM] [v1.0.7] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 2:17:43 PM] [API] Running Vitest v1.5.1 (my-frontend-app/vite.config.ts) with Node.js: /home/my-username/.nvm/versions/node/v20.14.0/bin/node
[INFO 2:17:43 PM] [API] Vitest v1.5.1 (my-frontend-app/vite.config.ts) process 1466673 created
[INFO 2:18:00 PM] [API] Collecting tests: src/api/utils/findEnv.test.ts
[Worker] 
node:internal/event_target:1099
  process.nextTick(() => { throw err; });
                           ^
Error: Cannot find module '/home/my-username/repos/my-frontend-app/node_modules/tinypool/dist/esm/entry/worker.js'
    at Function._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Function._load (node:internal/modules/cjs/loader:986:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:186:26)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28)
Emitted 'error' event on Tinypool instance at:
    at EventEmitterReferencingAsyncResource.runInAsyncScope (node:async_hooks:206:9)
    at Tinypool.emit (file:///home/my-username/repos/my-frontend-app/node_modules/tinypool/dist/esm/index.js:61:31)
    at Worker.<anonymous> (file:///home/my-username/repos/my-frontend-app/node_modules/tinypool/dist/esm/index.js:752:30)
    at Worker.emit (node:events:519:28)
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:825:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v20.14.0

Version

1.0.7

Validations