MS in CS specializing in Machine Learning (and Computational Perception and Robotics). Interested in Node.js, TypeScript, AWS, React, Brewing, DnD'ing. I ♥️ CDK and Serverless #AWSCommunityBuilder
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!
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.
"""
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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!
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.