#Using NX monorepo, in your modules do NOT use Class.name as your injection token/provider name.

10 messages · Page 1 of 1 (latest)

spice steeple
#

It worked great when I was working on one nest application at a time, but it all broke once webpack started failing to resolve dependencies for these injection tokens. The errors were arcane, and it was a day of debugging.

The solution was to simply use a string.

hollow plank
#

Nx uses webpack, and when optimize: true is set (which is what Nx tells webpack to do on production configurations) then class names get minimized. Nest suggests you use the class reference instead of its name as the injection token

spice steeple
#

I guess I assumed it was alright due to the following documentation for Mongoose:

hollow plank
#

Ah, that's fair. Generally, for those it's fine, and technically, so long as you always use the same class where you mean to it should all work the same, but it can make debugging a little funky sometimes.

#

Funny enough though, I haven't seen that in my server, so 🤷 though that may be more related to how I have my logging set up at the moment.

spice steeple
#

So, I probably had some areas of poor monorepo hygene, but essentially apps that did not have any shared dependencies with one another, were trying to resolve classes (and their names) that were not in scope. This could be due the minification that you're referring to.

hollow plank
#

Yeah, I think generally just sounds like poor monorepo hygine, like you said

spice steeple
#

Well, thanks for your time. Take care!

spice steeple
#

I have more details pertaining to this issue, it appears that if I have a service which has another service injected into it. All of my Nest applications in my NX monorepo will fail to build due to the class reference being undefined due to the export order of my shared lib.

These two screenshots simply describe the problem and the solution. A few interesting notes, the dependencies to focus on are the ones with the comments. The Header service is a dependency used in various services, however this example I want to call the attention to only those two. The youtube service has no references to the TwitchRequestService however is trying to resolve the class reference due to webpack.

This means that the exports of a shared lib must be in order from "most dependant" to "least dependant". Hope this helps someone.