You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
RUN v2.1.2 /home/steve192/development/vite-project
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Errors ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: Cannot find module '/steve192/development/vite-project/node_modules/vitest/dist/spy.js' imported from /home/steve192/development/vite-project/node_modules/vite-node/dist/client.mjs
❯ new NodeError node:internal/errors:405:5
❯ finalizeResolution node:internal/modules/esm/resolve:327:11
❯ moduleResolve node:internal/modules/esm/resolve:980:10
❯ defaultResolve node:internal/modules/esm/resolve:1193:11
❯ ModuleLoader.defaultResolve node:internal/modules/esm/loader:404:12
❯ ModuleLoader.resolve node:internal/modules/esm/loader:373:25
❯ ModuleLoader.getModuleJob node:internal/modules/esm/loader:250:38
❯ ModuleLoader.import node:internal/modules/esm/loader:336:34
❯ importModuleDynamically node:internal/modules/esm/translators:143:35
❯ importModuleDynamicallyCallback node:internal/modules/esm/utils:176:14
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Serialized Error: { url: 'file:///steve192/development/vite-project/node_modules/vitest/dist/spy.js', code: 'ERR_MODULE_NOT_FOUND' }
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Test Files no tests
Tests no tests
Errors 1 error
Start at 11:49:38
Duration 141ms (transform 11ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)
JUNIT report written to /home/steve192/development/vite-project/reports/test-results/unit/report.xml
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' }
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
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
The text was updated successfully, but these errors were encountered: