Skip to content

vite.config.ts should resolve alias from compilerOptions.paths in tsconfig.json #16718

@FreeJ1nG

Description

@FreeJ1nG

Description

Some plugin configurations require a complex object that might be split across the codebase
For instance, CRXJS Vite Plugin requires a manifest.json file, which might/might not require an (possible aliased) import from another file

Reproduction link here

Right now, vite does not resolve alias paths within vite.config.ts or it's dependencies

- src/
  - some-other-module/
    - foo.ts
  - config/
    - index.ts
- vite.config.ts
- tsconfig.json

Example of such case:

// src/config/index.ts
// throws an error even when tsconfig.json defines compilerOptions.paths properly
import { Something } from "@/some-other-module/foo"; 

...

// vite.config.ts
import { someConfig } from "./src/config";
...

Example of another case:

// vite.config.ts
// throws an error even when tsconfig.json defines compilerOptions.paths properly
import { someConfig } from "@/config";
...

Both cases will throw error when running an instance of the vite server

Suggested solution

Maybe consider using compilerOptions.paths to resolve the imports in vite.config.ts somewhere in the plugin pipeline

Alternative

I'm also considering creating a plugin that creates a workaround, still not 100% sure on how to accomplish this though

Additional context

I've received quite a bit of concern and confusion regarding consumers of vite not being able to utilize aliases in vite.config.ts, and I believe it'd be an issue worth looking at

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions