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

viteOverrides option in startVitest doesn't affect browser mode config #5015

Closed
6 tasks done
Florent-Bouisset opened this issue Jan 19, 2024 · 3 comments
Closed
6 tasks done
Labels
feat: browser Issues and PRs related to the browser runner p2-to-be-discussed Enhancement under consideration (priority)

Comments

@Florent-Bouisset
Copy link

Describe the bug

When using the experimental "browser mode", the import of custom files is not working although I have added a vite plugin that is telling how this import should be handled.

Importing a file like so works well in non browser mode, but it's not working in browser mode.

import bifExample from './example.bif?arraybuffer'

Result in this error in browser mode:

error log: [vite] Internal server error: Failed to parse source for import analysis because the content contains 
invalid JS syntax. You may need to install appropriate plugins to handle the .bif?arraybuffer file format, 
or if it's an asset, add "**/*.bif?arraybuffer" to  assetsInclude in your configuration. 
Plugin: vite:import-analysis

Reproduction

https://github.com/Florent-Bouisset/bug-vitest-repo

npm i
npm run test:node # works normally
npm run test:browser # error

System Info

System:
    OS: macOS 14.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 47.25 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.0.0 - ~/.nvm/versions/node/v21.0.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v21.0.0/bin/yarn
    npm: 10.2.0 - ~/.nvm/versions/node/v21.0.0/bin/npm
  Browsers:
    Chrome: 120.0.6099.234
    Safari: 17.2.1
  npmPackages:
    @vitest/browser: 1.2.1 => 1.2.1 
    vitest: 1.2.1 => 1.2.1

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

Interesting usage of a public API 🤔 "viteOverrides" is only applied to the main server, the browser has its own separate server and it doesn't use this option at all (aliases also won't work for example). This is probably a bug, but I am not sure.

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Jan 20, 2024

Just in case, I verified that plugin usage with normal vite.config.ts is working fine for browser mode
https://stackblitz.com/edit/vitest-dev-vitest-fg3qe5?file=vite.config.ts

As @sheremet-va suggested, I think the issue is more like startVitest + viteOverrides API and how it can affect browser mode config.

While thinking about how browser mode server config can be affected by main server config, I thought we can potentially pass project.server.config.plugins to browser mode server around here, but of course, this is not supposed to work for many reason, such as, these plugins are already "instantiated" ones and cannot be reused for a different plugin container, then also these plugins already includes vite/vitest's internal plugins.

export async function createBrowserServer(project: WorkspaceProject, configFile: string | undefined) {

I feel this is inherent limitation of inline config and running multiple vite servers, which actually comes up sometimes in the ecosystem such as remix-run/remix#7990 (Remix was reusing already instantiated plugins in two servers) and also solidjs/solid-start#1198 (I'm not too familiar but solid/vinxi also has multiple servers). So this user's browser mode use case might be difficult to support without tweaking API in some explicit way.

@hi-ogawa hi-ogawa added the feat: browser Issues and PRs related to the browser runner label Jan 31, 2024
@hi-ogawa hi-ogawa changed the title Vitest fail to import in browser mode when using plugins viteOverrides option in startVitest doesn't affect browser mode config Feb 1, 2024
@sheremet-va sheremet-va added the p2-to-be-discussed Enhancement under consideration (priority) label Feb 12, 2024
@sheremet-va sheremet-va moved this to P2 - 3 in Team Board Feb 12, 2024
@sheremet-va sheremet-va moved this from P2 - 3 to Rejected in Team Board Apr 25, 2024
@sheremet-va
Copy link
Member

There is a concept of a "core workspace project" in Vitest API. This is a project that is responsible for higher-level features that you cannot have on a workspace level like a global setup or coverage. The browser server is part of a workspace project and is not affected by the viteOverrides - it only affects the "core project".

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: browser Issues and PRs related to the browser runner p2-to-be-discussed Enhancement under consideration (priority)
Projects
Archived in project
Development

No branches or pull requests

3 participants