6

When I use react framework and I do a npm install, about 27,000 files are generated on my node_modules. The size is not the concern, rather, the amount of files. If I have to copy that directory somewhere else, it takes a very long time due to that many files. If I have to delete it, that takes long as well. My Google drive sync does not have an "exclude folder" option for node_modules, therefore, syncing that with cloud also takes a VERY long time. I also don't like the fact that each react project I have, will generate another 27,000 files.

Does anyone have a solution for this? Basically, I don't want 27,000 files for every react project I create. I was thinking of just having one GLOBAL node_modules somewhere and ALL react apps will call that instead of creating their own node_modules folder.

Here is my package.json

{
  "name": "react-typescript-tutorial",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "enzyme": "^3.3.0",
    "react": "^16.4.1",
    "react-bootstrap": "^0.32.1",
    "react-dom": "^16.4.1",
    "react-redux": "^5.0.2",
    "react-router-dom": "^4.3.1",
    "react-router-redux": "^5.0.0-alpha.9",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts-ts start",
    "build": "react-scripts-ts build",
    "test": "react-scripts-ts test --env=jsdom",
    "eject": "react-scripts-ts eject"
  }
}

P.S. I'm willing to change to a different package manager like yarn or whatever, if it can generate less files.

FerX32
  • 1,407
  • 3
  • 18
  • 28
  • 4
    Are you storing your projects in Google Drive? I recommend using e.g. GitHub instead, and using a `.gitignore` file with `node_modules` in it. – Tholle Jul 10 '18 at 16:14
  • We use TFS on our main projects. This is just an example I guess. Also, when we do things like backup hard drives, it takes a lot longer with so many files. – FerX32 Jul 10 '18 at 16:18
  • No. Those files are dependencies, and as such will be required no matter what package manager you use. The most you can do is "ignore" said folder in the sync/backup/whatever tools you use. If they don't have such support... use another tool... or don't use react – Kevin B Jul 10 '18 at 16:22
  • Ah, I see. I don't know if you can store all dependencies in one place for every project, but it might be worth using a [script like this](https://stackoverflow.com/questions/42950501/delete-node-modules-folder-recursively-from-a-specified-path-using-command-line#answer-43561012) before backup. – Tholle Jul 10 '18 at 16:22
  • 1
    Thanks @Tholle, that helps a bit for sure. Also, I'm not sure why this is being downvoted so much, obviously it is a concern to some people for various reason if posts like that exists in the first place. – FerX32 Jul 10 '18 at 16:24

3 Answers3

4

I agree, it's ridiculous how many files they make. It would be better if they wouldn't write just ten lines in a new file. I think the structure is not very robust. And the poor file system have to make all these files. Luckily I don't use hard drives anymore, but still it takes much longer time with many files.

edit: So I just checked my react ++ mobx, +decorators project, and it had node_modules folder for a small project for duplicate files. It had 16000 duplicate files, with the possibility to clean 150MB of 280MB. I think that's just absurdly unnecessary. Proboble multiple versions for each dependency when they could have just used the same.

agiopnl
  • 1,190
  • 9
  • 18
2

Try this:

  1. Install all of your dependencies in global.
  2. Go to each module of it (just module in dependencies ) and run npm link you registed that module.
  3. Go to your project and run npm link <name module need link>
  4. Done, npm created link to your dependencies

I don't Google drive sync it or not, but npm don't need install it.

You can try Exclude folder in Folder or Exclude subfolder from sync, but keep this folder in PC

Or you don't use npm install to install module. You should install global for all and set enviroment variable NODE_PATH to global node_modules. When require, node will call it.

hong4rc
  • 3,999
  • 4
  • 21
  • 40
1

I'm considering learning something else.

Elm sounds promising for organized and tidy filesystem. And googles polymer-project aim to change the web into not needing any framework at all.

agiopnl
  • 1,190
  • 9
  • 18