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

Mixing browser and non-browser projects in vitest workspace causes error #5734

Open
cuberoot opened this issue May 16, 2024 · 2 comments
Open
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@cuberoot
Copy link

Describe the bug

I have encountered a bug in vite/vitest that occurs when I have a vitest.workspace.ts that references at least two vitest.config.ts project files that use the node environment and one vitest.config.ts project file that executes tests in a browser.

When I run vitest I get the following error:

 DEV  v1.6.0 /Users/mitaylor/Temp/VitestRaceBug
      [browser] Browser runner started at http://localhost:5173/

 ✓ |test1| src/bubblesort.test.ts (5)
 ✓ |test3| src/insertionsort.test.ts (3)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot read properties of undefined (reading 'imports')
 ❯ node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:52698:47
 ❯ process.processTicksAndRejections node:internal/process/task_queues:95:5

I debugged a little and the issue seems to occur in runOptimizeDeps. The build outputs have relative paths instead of normalized paths. When I remove the project that has browser tests in it, then the outputs in runOptimizeDeps have normalized paths relative to the root of the project. They don't contain any .. paths.

Screenshot 2024-05-16 at 6 44 22 PM

Reproduction

I have managed to create a minimal project that demonstrates the problem. It is available here: https://github.com/cuberoot/vitest-race-issue

System Info

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 453.30 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.0/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    bun: 1.1.4 - ~/.bun/bin/bun
  Browsers:
    Chrome: 125.0.6422.60
    Chrome Canary: 126.0.6478.0
    Firefox Nightly: 127.0a1
    Safari: 17.4.1
    Safari Technology Preview: 17.4
  npmPackages:
    @vitest/browser: ^1.6.0 => 1.6.0
    vite: ^5.2.11 => 5.2.11
    vitest: ^1.6.0 => 1.6.0


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide/).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@cuberoot
Copy link
Author

As a workaround, you can run just the browser-based tests by themselves. That will cache the necessary optimized dependencies in node_modules/.vite. After that, you can run all of your tests together and they will complete.

@sheremet-va
Copy link
Member

Thank you for the reproduction! I also noticed the same error in our tests from time to time, but did not have time to investigate,

@sheremet-va sheremet-va added p3-minor-bug An edge case that only affects very specific usage (priority) feat: browser Issues and PRs related to the browser runner and removed pending triage labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: browser Issues and PRs related to the browser runner p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants