Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rudygoa's avatar

Need to deploy node_modules on production as part of GIT and not use 'npm install'

For our project, we need to keep node_modules as part of the code base and not be in .gitignore. When we do that, node command like "node socket.js" does not work because it is not able to find the modules. Does "npm install" do something more than just copying the modules in node_modules?

I can see that the module folders are there, but still it give module not found error. Like "Error: Cannot find module 'express'"

Look forward to you response. Thank you.

0 likes
3 replies
Olixr's avatar

It's generally not a recommended practice to commit your node_modules directory anymore. When you run npm install there are tasks behind the scenes that node does to compile some scripts. This can differ on windows /linux / mac.

It is possible that this is the issue you are encountering.

Could I ask the reason for needing to commit this to your project base?

jekinney's avatar

@Olixr not to step on the op but lots of use cases.

Want to easily modify CSS and version control? On save run gulp command to use elixir.

Socket io server and intergrading into laravel.

Server side node packages like socket above,

Easily update packages like mentioned in first one.

I understand what your saying, but sometimes the pros override the cons.

@RUDYGOA

Some node packages need to be globally installed and also a local package. Also be sure that any requirements aren't under dev dependencies as it's not typical to deploy and run npm.

Olixr's avatar

I see what your saying. I just personally have not run into this use case before thats why I was curious.

This is good info for me though as well. I expect as I dig into Vue and Echo more that I may run into a similar case.

1 like

Please or to participate in this conversation.