question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possibility to define additional node paths

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Jun 13, 2022

Can you elaborate on why you think Vite shouldn’t provide any other way of resolving?

Mostly because resolve.alias already covers a lot of base, and Vite is trying to minimize the config surface area.

(Do you think this should be handled by plugins or do you think the current feature set is enough?)…

I think both. And with plugins like https://github.com/Subwaytime/vite-aliases should cover the heavylifting too.

Usually I’d alias src as @ and call it a day, as there’s no need to add more complexity for code preference. But the option is always available with plugins 🙂

1reaction
KingSoracommented, Jun 13, 2022

@bluwy Thanks for your reply! As you can imagine, aliasing every directory under ./src manually is not really the way to go for me. Can you elaborate on why you think Vite shouldn’t provide any other way of resolving? (Do you think this should be handled by plugins or do you think the current feature set is enough?)…

I would have even more usecases for the moduleDirectories feature I described.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to describe a set of paths in a graph with as few nodes as ...
Some of the nodes in the graph may belong to more than one tree. I am trying to describe a subset of paths...
Read more >
Better local require() paths for Node.js - gists · GitHub
Possible solutions. Ideally, I'd like to have the same basepath from which I require() all my modules. Like any other language environment out ......
Read more >
Finding a Simple Path with Multiple Must- include Nodes
Abstract. This document presents an algorithm to find a simple path in the given network with multiple must-include nodes. The problem of finding...
Read more >
Path definition statements - IBM
PATH definition statements are the representations of the routes VTAM® takes to communicate with other subarea nodes. Paths are defined only for hosts...
Read more >
How to include the path for the node binary npm was executed ...
In Visual Studio, go to TOOLS > OPTIONS > search for EXTERNAL WEB TOOLS > and ensure "C:\Program Files\nodejs" (or wherever nodejs.org ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found