FerX32
FerX32

Reputation: 1407

node_modules has too many files when using react framework

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.

Upvotes: 5

Views: 3947

Answers (3)

agiopnl
agiopnl

Reputation: 1344

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.

Upvotes: 1

agiopnl
agiopnl

Reputation: 1344

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.

Upvotes: 4

hong4rc
hong4rc

Reputation: 4103

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.

Upvotes: 2

Related Questions