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

stueynet's avatar

#WTFNPM

I am throwing this in Envoyer because its related. So I have a really basic Laravel 5.3 site. Totally static. Nothing fancy happening. Here is my package.json

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "bootstrap-sass": "^3.3.7",
    "del": "^2.2.0",
    "gulp": "^3.9.1",
    "gulp-autoprefixer": "^3.1.0",
    "laravel-elixir": "^6.0.0-9",
    "laravel-elixir-browsersync-official": "^1.0.0",
    "laravel-elixir-imagemin": "^0.2.3"
  }
}

That seemingly simple package.json creates a node_modules folder that is 130MB on disk, and a tree that numbers in the thousands. What. The. Hell.

First off that is grotesque. I don't even know what to say.

Second, I am running Envoyer for the production version of the site, and obviously every deploy will generate 130MB of node_modules. So I am thinking of adding a hook to remove the node modules at the end of each deployment. The only purpose of node modules is to let gulp do its thing so I don't see this causing any huge issues but just wanted to open the discussion and see if anyone has any thoughts on this. Just wanted to see if anyone has any thoughts.

0 likes
7 replies
SaeedPrez's avatar

Make sure /node_modules is in your .gitignore file.

I'm not using Envoyer but I do use Forge and DigitalOcean and with a few sites online, none of them have the node_modules folder on the server.

1 like
stueynet's avatar

@SaeedPrez how would your application build without node_modules on the server? When you push code to the server it builds your assets and that often requires node_modules. Gulp for example. So not sure what you mean. My node_modules is not in my repo. But every time the server does a new build, it of course has to create node_modules in preparation for running gulp.

SaeedPrez's avatar

I run gulp on development, it builds everything I need there so I can test it and then if everything is OK I push the production-ready project & assets to the repo which then goes to the server.

stueynet's avatar
stueynet
OP
Best Answer
Level 5

Just to follow up I have just added rm -r node_modules to my post activation hook in Envoyer and it seems to be just fine. Easy fix.

But node_modules is still gross.

stueynet's avatar

@SaeedPrez Envoyer does this for you. It runs your builds. Runs tests. Then deploys the production site. You can set it to deploy immediately or require some other hook.

SaeedPrez's avatar

Alright, I guess that is a good solution then to remove it when everything is ready for production. But yeah, I don't like the size of node_modules either.

1 like
MikeHopley's avatar

It's especially fun on Windows when the node_modules folder names get longer than 256 characters, at which point they're not allowed to exist. o_O

Please or to participate in this conversation.