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

Vitest fails to access internal state when running yarn web with React Native #5402

Closed
amehmeto opened this issue Mar 18, 2024 · 0 comments
Closed

Comments

@amehmeto
Copy link

Describe the bug

I'm encountering an issue where Vitest fails to access its internal state when I run my application using yarn web.

The error message suggests that Vitest is being imported directly without running the vitest command, or that it's being imported inside a globalSetup function.

However, I'm not doing either of these things in my code.

I have another test file that is working fine, so the issue seems to be specific to one test file (blocklist.view-model.test.ts). The error occurs in the browser console when I run yarn web.

Reproduction

You can find the repository at [https://github.com/amehmeto/TiedSiren].

The issue can be reproduced by running yarn web and checking the browser console.

The problematic test file is blocklist.view-model.test.ts in the src/react-view/screens/Blocklists/BlocklistScreen/ directory.

System Info

➜  TiedSiren git:(main) ✗ npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers

  System:
    OS: macOS 14.3.1
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 44.55 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.1 - ~/Library/Caches/fnm_multishells/959_1710793882934/bin/node
    Yarn: 1.22.17 - ~/.yarn/bin/yarn
    npm: 10.2.4 - ~/Library/Caches/fnm_multishells/959_1710793882934/bin/npm
    bun: 1.0.27 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 102.1.39.111
    Chrome: 122.0.6261.129
    Safari: 17.3.1
  npmPackages:
    vitest: ^1.2.2 => 1.4.0

➜  TiedSiren git:(main) ✗

Stack trace from Opera Browser when trying to run yarn start web

Uncaught Error: Vitest failed to access its internal state.

One of the following is possible:
- "vitest" is imported directly without running "vitest" command
- "vitest" is imported inside "globalSetup" (to fix this, use "setupFiles" instead, because "globalSetup" runs in a different context)
- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues

    at getWorkerState (global.CkGT_TMy.js:5:1)
    at getCurrentEnvironment (global.CkGT_TMy.js:19:1)
    at createExpect (vi.JYQecGiw.js:388:1)
    at ./node_modules/vitest/dist/vendor/vi.JYQecGiw.js (vi.JYQecGiw.js:426:1)
    at __webpack_require__ (bootstrap:22:1)
    at fn (hot module replacement:61:1)
    at ./src/react-view/screens/Blocklists/BlocklistScreen/blocklist.view-model.test.ts (BlocklistScreen.tsx:83:1)
    at __webpack_require__ (bootstrap:22:1)
    at fn (hot module replacement:61:1)
    at ./src/react-view/screens/Blocklists/BlocklistScreen/blocklist.view-model.ts (blocklist.view-model.test.ts:76:1)


### Used Package Manager

yarn

### 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.
@github-actions github-actions bot locked and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant