Closed kasir-barati closed 1 year ago
Please link to the tsconfig lines that you expected this plugin to resolve express
with
Please link to the tsconfig lines that you expected this plugin to resolve
express
with
https://github.com/kasir-barati/bugs/blob/vite-tsconfig-paths/apps/frontend/tsconfig.json#L39
I never wanted it to resolve express
. I just wanted to have access to the backend codes and import things like:
import { BACKEND_API_PREFIX } from 'backend/src/main';
I guess it is trying to find express in the frontend dependencies and obviously I have not it there. I am just thinking maybe if I create a new ts file and export that string from that file it won't complain. I'll try and tell you what happened. All in all it would be so lame if the problem resolves because then it will be a hassle to export shared things in a separate file or directory
Vite doesn't tree-shake in dev server mode, so you're importing your entire backend into your frontend, hence the attempt to resolve express
. It's unrelated to this plugin.
@aleclarson Thanks for the heads up. You're right. Here is the proof: https://github.com/kasir-barati/bugs/commit/c61c819dd6deb2f81f962e16fc5afc170aeba914
BTW just one thing is bugging me, when you told me that "Vite doesn't tree-shake in dev server mode", does it mean that I can hope that it will work in prod?
Dummy question but just to make sure
No, because there's a top-level side effect which prevents tree-shaking of backend stuff: https://github.com/kasir-barati/bugs/blob/c61c819dd6deb2f81f962e16fc5afc170aeba914/apps/backend/src/main.ts#L75
Easiest solution is to move the BACKEND_API_PREFIX to its own file
(oh, I see you did that already 😄 )
@aleclarson Suggestion, Update the doc to contains this pseudo issue/bug just to prevent others falls into the same trap :joy:
The Vite docs could use a Tree Shaking page that describes common pitfalls. The hard part about this pitfall is it looks like a resolution bug, but it's actually a misunderstanding of Vite's tree-shaking, so the people having this problem would be looking in the wrong place.
But none of that is specifically related to this plugin :)
Hey @aleclarson,
As you requested I created a reproducible repo. Please follow the instructions in the readme.md.
Here is the error message:
And here is the result when I run
DEBUG=vite-tsconfig-paths pnpm start:frontend
: