Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly build NestJS app for production with node_modules dependencies in bundle?

After nest build or nest build --webpack dist folder does not contain all required modules and I got Error: Cannot find module '@nestjs/core' when trying to run node main.js.

I could not find any clear instructions on https://docs.nestjs.com/ on how to correctly build app for production, so maybe I missed something?

like image 512
Dimanoid Avatar asked Jan 07 '20 19:01

Dimanoid


People also ask

How do I deploy NestJS app?

To do this: Create a new Git repository through your Git provider. Run git remote add origin <Your Git repository URL> to link the newly created repository with the repository the NestJS CLI initiated for you when creating the project. Commit your changes and push to the repository.

How does NestJS build work?

NestJS is a backend framework for creating scalable applications. It works as an abstraction over the underlying HTTP server library. Currently, it supports two libraries — Express and Fastify — while still enabling developers to use their own APIs when needed.


1 Answers

Out of the box, nest cli does not support including the node_modules dependencies into the dist bundle.


However, there are some community examples of custom webpack configs that include the dependencies in the bundle, e.g. bundled-nest. As described in this issue, it is necessary to include the webpack.IgnorePlugin to whitelist unused dynamic libraries.

like image 74
Kim Kern Avatar answered Sep 21 '22 11:09

Kim Kern