Skip to content

Possibility to define additional node paths #8439

@KingSora

Description

@KingSora

Clear and concise description of the problem

I've tried to replace my current bundler (rollup) with vite and got stuck with path resolution.
My setup is quite basic. I'm using absolute import paths in my project:

import { something } from 'someDir/someFile'; 

The relative file system path of this import would be ./src/someDir/someFile.

As you can see, I can omit the ./src/ part here. I did this by using the moduleDirectories prop from the @rollup/plugin-node-resolve. Unfortunately vite isn't providing this functionality out of the box which is in my opinion a key feature for every bundler.

Bundlers which are providing this feature:

This is also supported by Eslint with the eslint-import-resolver-node plugin (moduleDirectory option)

Suggested solution

Provide this feature "natively" in the vite config. Something like resolve.moduleDirectories or resolve.nodePaths.

Alternative

It seems like you can use the @rollup/plugin-node-resolve plugin here, but it still feels weird to have this key feature not supported. Additionally since vite is doing quite some resolve logic itself I'm in fear of something not working properly by using the plugin.

You could also use aliases, but is this the "right" way? - With this solution I would be forced to rewrite all of my imports.

Additional context

No response

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