sodatea / vite-jest

First-class Vite integration for Jest
MIT License
401 stars 51 forks source link

Validation error when running vite-jest #29

Open dospunk opened 2 years ago

dospunk commented 2 years ago

When I try to run vite-jest I'm getting this error:

 Validation Error:

  Module /path-to-my-repo/node_modules/vite-jest/index.js in the transform option was not found.
         <rootDir> is: path-to-my-repo

  Configuration Documentation:
  https://jestjs.io/docs/configuration

path-to-my-repo\node_modules\execa\lib\error.js:60
                error = new Error(message);
                        ^

Error: Command failed with exit code 1: node --experimental-vm-modules path-to-my-repo\node_modules\jest\bin\jest.js
    at makeError (path-to-my-repo\node_modules\execa\lib\error.js:60:11)
    at Function.module.exports.sync (path-to-my-repo\node_modules\execa\index.js:194:17)
    at file:///path-to-my-repo/node_modules/vite-jest/bin/vite-jest.js:11:7
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async Object.loadESM (node:internal/process/esm_loader:68:5)
    at async handleMainPromise (node:internal/modules/run_main:63:12) {
  shortMessage: 'Command failed with exit code 1: node --experimental-vm-modules path-to-my-repo\\node_modules\\jest\\bin\\jest.js',
  command: 'node --experimental-vm-modules path-to-my-repo\\node_modules\\jest\\bin\\jest.js',
  escapedCommand: 'node --experimental-vm-modules "path-to-my-repo\\node_modules\\jest\\bin\\jest.js"',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

It seems to suggest that vite-jest isn't installed, but it is so I'm kind of at a loss

jacokok commented 2 years ago

Try changing your preset in jest.config.js to the below.

preset: "./node_modules/vite-jest/index.js",

This worked for me. Saw this at https://github.com/sodatea/vite-jest/issues/10