-
Notifications
You must be signed in to change notification settings - Fork 69
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
How to properly make module alias work when building the dist/build folder? #74
Comments
@arvi Looks like in your To sum up, TS is using aliases from So in your
|
Hello @ilearnio . Thanks for your response. You mean replace
This worked and compiled correctly. The issue now is when I run dev again, it doesn't respect the paths in the
But still nope. I can only work on my project in dev when I change back the |
@arvi It could be because you are using ts-node which compiles TS in background. Since you have compliled dist folder already you may not need ts-node at all. Is it possible to change it so your |
Interesting discussion ! Another possibility is to look into something like tsconfig-paths. It seems designed for this use-case. |
Here's an example @arvi : https://github.com/Kehrlann/module-alias-74 Edit for more context:
|
Oh my gosh! 😄 I can't thank you enough! It finally worked! Hope you have that answer on my SO question 😅 so I can upvote you haha. But anyways, I have posted your answer in that thread. Thanks for all your help @ilearnio and @Kehrlann . I appreciate it a lot. |
Hey, I was looking at your solution but as tsconfig-paths is installed in the dev dependencies, when building your code with docker, for example, this package won't be able in a production environment. |
Good point @vschoener ; I should probably include |
For anyone having this issue, this is another way to do this, put it in the entry file at the top before other imports.
|
Also a good suggestion @rebirthtobi , thank you ! It seems the two paths in your |
@rebirthtobi Thank you very much! This worked perfectly for me!
Just replaced this for this
|
What happens if the imported module is in a parent directory? For example I have a common module that I use both in frontend and backend. Directory structure:
|
I was experimenting on module alias for typescript and it works during dev, but when I try to build it I always get cannot find module because it is pointing to
src
file even on build. I tried experimenting on different configs and searched all over but can't still get it to work. I thought I should just ask here for advice.Here is my project structure:
Snippet of my
package.json
My
tsconfig.json
My
.eslintrc
(not sure if it matters or relevant to this problem)Sample of how I use it
I hope you can help me point out where I went wrong with my config. Thanks a lot.
The text was updated successfully, but these errors were encountered: