-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Vite – can't import TypeScript paths in vite.config files #17019
Comments
Linking this issue here. |
@danr-za I remember we had solved this, but now it fails due to the |
hmm not that I am aware of yet. I can check |
@mandarini Maybe it'll help you if I add that no files outside of 'src' are being treated with TypeScript. Just tried having Tailwind config import my TS theme (relative import) and it also fails. |
That's not fixed yet, it's partly fixed. Not sure how to fix atm, will revisit. |
Updated repro: https://github.com/mandarini/vite-paths |
Update on this issue: @jaysoo looked into it as well, and I present here the findings: This is an issue with monorepos in general, not just Nx. There's an open, existing issue, on the Vite side: vitejs/vite#5370 Because of this line here:
If your import starts with @patak-dev mentioning you here, just in case! :) |
Thanks for the update @mandarini |
Hi, I don't really know whether to comment in this PR or in #17844 I looked at the open PR in vite's repo, and it definitely would fix my issue if they would fix it, but I have the following scenario: I'm working with NX to create an integrated monorepo where I have (for now) a single app and a single library.
this all works fine and well in build mode - I passed the buildFromSource option as false, forcing my lib to be built when the app it being built (nx is awesome BTW), but in dev mode, it looks like it fails to use the tmp folder with the generated tsconfig you can look at the demo here I'll add that type safety is incredibly important to me, so if you have a type safe way to solve my issue that goes around this vite problem, I'm all ears! thanks in advance! |
@barbados-clemens mentioning you here, just in case, for above comment! |
Oh I see, this is the ts file within the vite config not a source file importing the ts file. I'm not too sure. Let me see if it's semi related to the PR I mentioned above. Update: I didn't see anything obvious since the plugin resolved during vite lifecycles, and this error is happening before vite loads and runs the plugins. |
@barbados-clemens exactly, so it doesn't seem like it is vite's issue anymore, but NX's - of course, only because of the bypass (using buildFromSource: false and building the plugin), but still. I'll admit, I've had a hard time finding one so I might be totally wrong - I hope you can find the real cause and help me 🤞 |
Unfortunately this a limitation from how Vite loads config files. It uses a resolver to transform import paths to file system paths, but it never loads a tsconfig file to assess for it being a path alias defined in a tsconfig file. Therefore this is something outside of our control unfortunately. An issue is open on the vite repo about this issue already: vitejs/vite#5370 |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
When trying to import
@my/lib
insidevite.config.ts
and run "test", I am getting an error sayingWhen I try to run "build", I am getting
When using relative imports, all works fine.
Expected Behavior
Import paths are allowed in vite.config.ts.
GitHub Repo
https://github.com/tomekbuszewski/nx-vite-problem
Steps to Reproduce
vite.config
, import something using TS paths (@my/lib
);Nx Report
Failure Logs
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: