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

Module aliases fail to resolve in workspace setup with browser config #4744

Closed
6 tasks done
fubhy opened this issue Dec 14, 2023 · 2 comments · Fixed by #4947
Closed
6 tasks done

Module aliases fail to resolve in workspace setup with browser config #4744

fubhy opened this issue Dec 14, 2023 · 2 comments · Fixed by #4947
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome

Comments

@fubhy
Copy link
Contributor

fubhy commented Dec 14, 2023

Describe the bug

I'm trying to configure a monorepo workspace project from the root with all config in vitest.workspace.ts. My intent is to run the entire test suite in different environments to verify cross-platform compatibility. I want to configure this in the workspace config directly for more fine grained control instead of using cli options.

The bug is that any browser configuration (no matter which provider is used) fails to resolve module aliases if they are configured from the workspace root. It works if they are configured e.g. via a package specific vitest.config.ts file but not via the workspace root config.

The provided reproduction showcases that in the simplest way possible.

Reproduction

https://github.com/fubhy/vitest-workspace-repro

System Info

System:
    OS: macOS 14.0
    CPU: (12) arm64 Apple M2 Max
    Memory: 117.16 MB / 32.00 GB
    Shell: 3.6.1 - /nix/store/brlkinambh1hg2baqy43fyi7x66nqy8q-fish-3.6.1/bin/fish
  Binaries:
    Node: 20.9.0 - /etc/profiles/per-user/fubhy/bin/node
    npm: 10.1.0 - /etc/profiles/per-user/fubhy/bin/npm
    pnpm: 8.10.2 - /etc/profiles/per-user/fubhy/bin/pnpm
    bun: 1.0.11 - /etc/profiles/per-user/fubhy/bin/bun
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.0
  npmPackages:
    @vitest/browser: ^1.0.4 => 1.0.4
    vite: ^5.0.4 => 5.0.8
    vitest: 1.0.4 => 1.0.4

Used Package Manager

pnpm

Validations

@fubhy
Copy link
Contributor Author

fubhy commented Dec 14, 2023

There seems to be a problem with how the vitest server (createVitestServer) is initialized with project config. The server doesn't get the alias config passed to it at all because it appears to only load that from whatever it resolves as configFile in there.

By reading the source code there I managed to find a workaround. By dropping a vitest.aliases.ts file at the workspace root and pointing at that using the extends option for every project, it causes theconfigFile value to be resolved to that shared "alias" file.

That resolves my issue but it still appears to be a bug.

Workaround in repro: fubhy/vitest-workspace-repro#1

@fubhy
Copy link
Contributor Author

fubhy commented Dec 14, 2023

This is where things fall apart (unless using the extends workaround):

const configFile = options.extends
? resolve(dirname(options.workspaceConfigPath), options.extends)
: (typeof workspacePath === 'number' || workspacePath.endsWith('/'))
? false
: workspacePath

@sheremet-va sheremet-va added bug pr welcome p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Jan 3, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants