vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Vitest does not work when running from any CLI (Cannot find module @rollup)

Open Dimidrie opened this issue 1 year ago • 2 comments

Describe the bug

We are using Vitest in our project as a npm script. When running from Visual Studio Code, the tests run correctly. However, when we are trying to run the npm command that executes Vitest from a CLI outside of Visual Studio Code (for example, cmd or in a Jenkins pipeline), we get the following error:

Error: Cannot find module @rollup/rollup-win32-x64-msvc. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try npm i again after removing both package-lock.json and node_modules directory.

Reproduction

In VS Code (works):

  1. Open a new terminal
  2. Run command: npm run test (which runs vitest --run --no-isolate --no-file-parallelism)
  3. Vitest works

In any other CLI (doesn't work):

  1. Open CMD in the same directory as in VS Code
  2. Run command: npm run test
  3. Gives the error specified above (cannot find module @rollup)

System Info

Any

Used Package Manager

npm

Validations

Dimidrie avatar Jun 03 '24 14:06 Dimidrie

I'm also suffering the same issue, in Gitlab pipeline on image node:20.14.0.

⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯
Error: Cannot find module @rollup/rollup-linux-x64-gnu. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
    at requireWithFriendlyError (/builds/my-super-cool/app/node_modules/rollup/dist/native.js:59:9)
    at Object.<anonymous> (/builds/my-super-cool/app/node_modules/rollup/dist/native.js:68:76)
    ... 3 lines matching cause stack trace ...
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at cjsLoader (node:internal/modules/esm/translators:348:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:297:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24) {
  [cause]: Error: Cannot find module '@rollup/rollup-linux-x64-gnu'
  Require stack:
  - /builds/my-super-cool/app/node_modules/rollup/dist/native.js
      at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
      at Module._load (node:internal/modules/cjs/loader:986:27)
      at Module.require (node:internal/modules/cjs/loader:1233:19)
      at require (node:internal/modules/helpers:179:18)
      at requireWithFriendlyError (/builds/my-super-cool/app/node_modules/rollup/dist/native.js:41:10)
      at Object.<anonymous> (/builds/my-super-cool/app/node_modules/rollup/dist/native.js:68:76)
      at Module._compile (node:internal/modules/cjs/loader:1358:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
      at Module.load (node:internal/modules/cjs/loader:1208:32)
      at Module._load (node:internal/modules/cjs/loader:1024:12) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
      '/builds/my-super-cool/app/node_modules/rollup/dist/native.js'
    ]
  }
}

chriseagle avatar Jun 13 '24 19:06 chriseagle

Solved my issue by adding to package.json

`"optionalDependencies": {
    "@rollup/rollup-linux-x64-gnu": "^4.18.0"
  },

chriseagle avatar Jun 13 '24 19:06 chriseagle

Hello @Dimidrie. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

github-actions[bot] avatar Jul 28 '24 07:07 github-actions[bot]