Monorepo caching problems #149
AlexanderWeigand
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
@AlexanderWeigand I'm sorry you had a bad experience. I never have used Can you please varify that it works without the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
I just went through a 4 hour bug hunt and wanted to share my journey.
My setup
I'm using a monorepo and have a mobile (RN app), server (Express) and validation package.
Validation contains yup schemas which I use both in mobile and server.
Validation uses typesafe-i18n for localization of error messages. It's implemented as described here.
Mobile also uses typesafe-i18n with the react adapter.
The bug
When I ran my RN App from mobile, validation would throw an error, saying it could not find the described keys.
Understanding the bug
So after a while I found out, that I could access the mobile translations from validation (although the typing was completely incorrect).
This led me to looking into the source code of this package, where I found out, that a cache is used, when loading localizations.
Since I was using a monorepo, both validation and mobile packages were using the same typesafe-i18n package located in the root node_modules folder. Thus both were using the same cache, which led to this bug.
The solution
After understanding that the bug came from having one cache for two separate localizations, my solution was using the no-hoist option of yarn workspaces. I added typesafe-i18n to no-hoist and now both validation and mobile packages have separate typesafe-i18n packages in their node_modules and thus have their own cache.
What to do about this?
I would at least add a section in the docs about this pitfall, when using monorepos. You could also explicitly mention in the docs, that you are using a cache object when loading the localizations (or did i overlook this?). You could also provide an option to disable the caching. Using the no-hoist option is not too bad of a workaround, but I would still like to have a cleaner and in-built solution to this problem with a monorepo setup. I will let you decide how this solution should look and if it's worth it at all.
Other than that, I'm loving the library and want to thank you for what you're doing :)
Greetings,
Alex
Beta Was this translation helpful? Give feedback.
All reactions