Open steve192 opened 2 weeks ago
Can you provide a reproduction without Vitest? What you investigated seems right, but having a Vite only reproduction really helps us investigating the issue further.
For Vitest use case, we could suggest a workaround like base: process.env.VITEST ? undefined : "/home"
, but I assume it would be a blocker for Vite use cases anyways.
Describe the bug
Hi, I am having trouble with an application which has
base: '/home'
set in vite.config.ts. I build a simple example with vitest where spy.js of vitest cannot be imported when tests are run. But it also happens when you try to import scss files from libraries (but lets focus on the simple example with vitest).As a note, this issue is not related to vitest, but is just a simple way to reproduce the issue
npx vitest run
I found out, that the reason is, that the base path /home is part of where the project is located (/home/steve192/development/vite-project). You can see that somehow /home is removed from the path where the module is searched
Serialized Error: { url: 'file:///steve192/development/vite-project/node_modules/vitest/dist/spy.js', code: 'ERR_MODULE_NOT_FOUND' }
Reproduction
https://github.com/steve192/vite-project
Steps to reproduce
npx vitest run
System Info
Used Package Manager
npm
Logs
No response
Validations