Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run nestjs build without node_modules folder

I'm developing a Nestjs micro-service and need to run the build in dist folder using below command and it's working fine

node dist/main.js

Problem is, above command not working without the node_modules folder. Why can't we run the the build folder(dist) without node_modules folder?

This is the error I'm getting enter image description here

like image 824
Ajantha Bandara Avatar asked Aug 08 '26 08:08

Ajantha Bandara


2 Answers

This is Node code, which uses the node_modules folder to search for modules. It cannot run without it. You could try using something like pkg to package it into an executable. The dist folder just contains code, not modules.

like image 63
0xLogN Avatar answered Aug 09 '26 22:08

0xLogN


No, you can't. Node.js are depended on package.json for finding modules, which also depend on node_modules that store the module. Maybe you want to compile it as one ? Try this https://github.com/vercel/ncc. I never use it for Nest.js before, but you can try it.

like image 24
mandaputtra Avatar answered Aug 09 '26 23:08

mandaputtra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!