7

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

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

You can only run it without node_modules by rewriting the webpack.config.js, you may check this template nestjs-v9-webpack-boilerplate

1 Comment

Your answer could be improved by providing an example of the solution and how it helps the OP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.