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

Support for vite ModuleRunner or other configLoader alternative #7552

Open
4 tasks done
Carnageous opened this issue Feb 24, 2025 · 3 comments
Open
4 tasks done

Support for vite ModuleRunner or other configLoader alternative #7552

Carnageous opened this issue Feb 24, 2025 · 3 comments
Labels
enhancement: pending triage p2-to-be-discussed Enhancement under consideration (priority)

Comments

@Carnageous
Copy link

Clear and concise description of the problem

Vite introduced ModuleRunner recently, which is specifically useful for using vite with the option --configLoader runner so it can load .ts config files. I am, for example, using this approach to define a shared vite config from a package in a monorepo.

Now, with vitest's monorepo / project setup, it would be very helpful to load .ts config files from a sub-package using this approach, mainly because by default projects within a vitest workspace do not inherit all configurations but must be extended by a shared config (as per your documentation).

I like this design decision a lot, but having a shared config file in a monorepo is best done by defining it in a package that can be consumed by other packages.

Suggested solution

Allow vitest to load .ts files the same way vite can with the --configLoader runner flag. Or allow importing .ts files into vitest config files another way. An ideal config would look something like this:

import { defineProject, mergeConfig } from 'vitest/config';

import vitestConfigReact from '@my-monorepo/vitest-config/react-base';

// Note: This uses vitest's `defineProject`, not `defineConfig`, as workspace projects don't have all config options
export default mergeConfig(vitestConfigReact, defineProject({
  // ... my per-project-config
}));

Alternative

I am not at all fixed on supporting this ModuleRunner thing as I have no clue what the implications to Vitest would be. So any way to support .ts file imports would be great.

Additional context

No response

Validations

@Carnageous
Copy link
Author

I figured you might want to know which errors one would currently get.

When running vitest with a vitest.config.ts file at the monorepo root and a sub-package for the vitest config, an error would look like this:

> vitest

failed to load config from /monorepo/packages/package-a/vitest.config.ts
failed to load config from /monorepo/packages/package-b/vite.config.ts

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
AggregateError: Failed to initialize projects. There were errors during workspace setup. See below for more details.


errors]: [
    TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /monorepo/packages/vite-config/react.ts

The folder structure looks like this:

repo/
├─ package-b/
│  ├─ vitest.config.ts // imports shared config
├─ package-a/
│  ├─ vitest.config.ts // imports shared config
├─ vitest-config/
│  ├─ react.ts // shared config
├─ vitest.config.ts // workspace

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Feb 25, 2025

I think this is a matter of passing around configLoader flag to vite server config in two places, so probably we can allow this as Vitest cli flag

const config: ViteInlineConfig = {
configFile: configPath,

const config: ViteInlineConfig = {
...restOptions,
configFile,

@hi-ogawa hi-ogawa moved this to P2 - 2 in Team Board Feb 25, 2025
@hi-ogawa hi-ogawa added the p2-to-be-discussed Enhancement under consideration (priority) label Feb 25, 2025
@MQYForverT
Copy link

I also want to talk about this issue and look forward to updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement: pending triage p2-to-be-discussed Enhancement under consideration (priority)
Projects
Status: P2 - 2
Development

No branches or pull requests

3 participants