Skip to content

__vitest_browser_runner__.runTests is not a function when browser mode x customzied root #7807

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

Open
6 tasks done
Jinjiang opened this issue Apr 8, 2025 · 5 comments
Open
6 tasks done

Comments

@Jinjiang
Copy link

Jinjiang commented Apr 8, 2025

Describe the bug

when the root is specified to an outside dir x browser mode
https://github.com/Jinjiang/reproductions/tree/vitest-browser-20250408

(not sure whether it's same to #6674)

Reproduction

https://github.com/Jinjiang/reproductions/tree/vitest-browser-20250408

cd tool
pnpm install

# it works
pnpm test
# it works
pnpm test2
# it doesn't work
pnpm test3

error:

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.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: __vitest_browser_runner__.runTests is not a function
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

System Info

System:
    OS: macOS 15.5
    CPU: (8) arm64 Apple M1
    Memory: 98.09 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.local/share/mise/installs/node/22/bin/node
    Yarn: 1.22.18 - ~/.yarn/bin/yarn
    npm: 10.9.2 - ~/.local/share/mise/installs/node/22/bin/npm
    pnpm: 10.7.1 - ~/Library/pnpm/pnpm
    bun: 1.1.36 - ~/.local/share/mise/installs/bun/latest/bin/bun
  Browsers:
    Safari: 18.5
  npmPackages:
    @vitest/browser: ^3.1.1 => 3.1.1 
    playwright: ^1.51.1 => 1.51.1 
    vitest: ^3.1.1 => 3.1.1

Used Package Manager

pnpm

Validations

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Apr 8, 2025

Can you provide something more realistic? For example, should proejct/package.json and tool/package.json both have same vitest at least and managed by pnpm (so it points to the same node_modules/.pnpm/vitest...)?

@Jinjiang
Copy link
Author

Jinjiang commented Apr 8, 2025

Sure. In realistic, the vitest was called in a tool in node_modules. So basically vitest is a deep dependency. And the project itself could have no direct vitest dep or another vitest instance.

<real-project>
  src
    foo.spec.ts
  node_modules
    the-tool
      node_modules
        vitest

And it works always without browser mode. as the pnpm test2 shows.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Apr 8, 2025

Okay, I misunderstood the assumption then. In that case, I think users cannot have auto-completion of import "vitest", but is that expected? or does it somehow work fine with global typing?

@Jinjiang
Copy link
Author

Jinjiang commented Apr 8, 2025

I see. In this aspect, there could be another vitest instance in <project-root>/node_modules. I understand this is just for type checking?

Anyway, I've updated the reproduction this time there is a vitest instance in project and no test.globals in the vitest config. Still, pnpm test and pnpm test2 work and pnpm test3 doesn't.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Apr 8, 2025

Ah sorry, my question about auto-completion was just a side question to understand your use case better overall. (And not about judging intended Vitest behaivor per-se.)

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