Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain Modules / Files not found when apps base path is part of the directory where the project is located in #18279

Open
7 tasks done
steve192 opened this issue Oct 4, 2024 · 1 comment

Comments

@steve192
Copy link

steve192 commented Oct 4, 2024

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

 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' }

Reproduction

https://github.com/steve192/vite-project

Steps to reproduce

  • Clone project into a directory located in /home
  • Run npx vitest run

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (4) x64 11th Gen Intel(R) Core(TM) i5-11500H @ 2.90GHz
    Memory: 12.00 GB / 19.54 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.20.0 - ~/.nvm/versions/node/v18.20.0/bin/node
    Yarn: 1.22.22 - /mnt/c/Users/<redacted>/node/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v18.20.0/bin/npm
    pnpm: 9.9.0 - /mnt/c/Users/<redacted>/node/pnpm
  Browsers:
    Chrome: 120.0.6099.71
  npmPackages:
    @vitejs/plugin-react: ^4.3.2 => 4.3.2 
    vite: ^5.4.8 => 5.4.8

Used Package Manager

npm

Logs

No response

Validations

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Oct 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants