-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
CSS processors aren't considered installed if root is placed outside of vite.config's folder #2612
Comments
For reference: https://vitejs.dev/guide/#index-html-and-project-root The expected behavior is for root to be an entry point for the server, so I believe the server is using the wrong path to resolve plugins when compiling (which isn't necessarily the same path you use for import resolution). I'm not sure if it's only affecting css plugins/preprocessors - it was just the first thing that broke when I tried this setup out. Please ask if something isn't clear, I'd like to help. |
it works fine here |
Hello @bjarkihall. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by |
This can't be reproduced on codesandbox I believe, here's a repo (just like I described in the issue description): |
@HomyeeKing where was your package.json and where were you running vite from? Please note, that if the B folder has package.json or an ascendant does OR if sass is globally installed (which might be your case?) this won't reproduce as node will resolve the module from there (which is a false negative). |
yes, seems better to consider where you can do the same thing with |
@HomyeeKing yeah, the repro is just with the minimum amount of files to showcase the issue. In my original setup where the error occurred, there was a much larger monorepo where package.json was inside one "bundling" folder which has a task runner that builds multiple builds from multiple folders/projects - then vite is used to serve these different builds separately, which theoretically could be output into a completely different folder on the computer too. Previously, each output needed either a live-server or some configurations via IIS but vite works as a handy replacement for these typical static dev servers - it just needs a path to the index.html. :) Also, only 1 package.json + node_modules is needed to resolve the server's dependencies now too, regardless of "what" it is serving and from "where" - plus, vite can also handle everything being unbundled + css/js plugins, like sass/ts, etc. Thanks for looking into this and making the PR, I wasn't sure if this was the right way to do it and wanted feedback before submitting a fix. Do you know if other plugins (like js/imgs/wasm, etc.) that are being compiled are affected too? I did a short check and it doesn't seem like they are handled in the same way as css plugins, so I guess they're ok? |
yes, they are handled differently, you can look through the vite docs to see how the other assets are processed |
@HomyeeKing would it make more sense to simply use |
@bjarkihall : I didn't expand on that fork because using a global (and node dependent) variable in that place is not the best way to solve the issue. If that PR doesn't advance I may propose an alternative without this flaw |
Closed by #3988, please report back if you find issues @bjarkihall. Thanks @ferdinando-ferreira for the heads up 👍🏼 |
Describe the bug
<root> describes the path of index.html, essentially where the static file server is running but it's also used as the root when searching for npm packages, which I'd rather think would be where vite.config is actually placed (or at least it should be used as a fallback).
I looked for potential duplicates and we started off a discussion on discord but it makes sense to raise this as a bug report to either clarify if you'd like this functionality to work at all (or identify potential blockers for this) or mention the limitation and reason in the docs.
Reproduction
Lets say you have the following folder structure:
So the idea here is that you run npm/yarn in folder A but the root of index.html (and its relative resources) is inside folder B (or C,D,E..., depending on the vite.config <root>).
Folder A defines the dev-server and the other folder defines what's being served.
Everything seems to run smoothly but the compileCSS function seems to send config.root to loadPreprocessor which fails, since the css-plugin (e.g. sass) isn't installed in the <root> so an error is thrown:
Preprocessor dependency "${lang}" not found. Did you install it?
.Wouldn't it make sense if the process would also fallback to the node_modules where vite process is running, if the <root> is different?
A possible fix would be for loadPreprocessors to accept roots: string[] instead of root: string which would be used by require.resolve (or just add the fallback locally within the loader so you can keep the arg as a single root).
System Info
vite
version: master (2.1.2)Logs
The text was updated successfully, but these errors were encountered: