DEV Community

Discussion on: Migrating Full-Stack Apps from Poly-Repo to Mono-Repo

Collapse
 
martzcodes profile image
Matt Martz

thanks! I haven't really thought about this in a while...

the strategy i used above was to have it running as a dev-server via Nx... you could also build the api and just copy the built stuff to the docker image and then run that directly (making sure it bundles everything it needs)... that'd probably be the better way to do it. good question!

Collapse
 
asmisalan profile image
Alan Asmis • Edited

Hi Martz! It's me again with bad news! :/ nestjs (nodejs at the end) needs the node_module folder because the build does not add all the dependencies, some libraries like typeorm cause problems if you don't include the node_modules.

I found this github.com/ZenSoftware/bundled-nest

"""
In many real-world scenarios (depending on what libraries are being used), you should not bundle Node.js applications (not only NestJS applications) with all dependencies (external packages located in the node_modules folder). Although this may make your docker images smaller (due to tree-shaking), somewhat reduce the memory consumption, slightly increase the bootstrap time (which is particularly useful in the serverless environments), it won't work in combination with many popular libraries commonly used in the ecosystem. For instance, if you try to build NestJS (or just express) application with MongoDB, you will see the following error in your console:

Error: Cannot find module './drivers/node-mongodb-native/connection'
at webpackEmptyContext
Why? Because mongoose depends on mongodb which depends on kerberos (C++) and node-gyp.
"""

So the workaround that I found was to move all the angular dependencies to the DevDependency list and copy the node_modules as you did in this tutorial.