How to create global node_modules

This is not directly related to Ivan On Tech Academy course but I thought I want to address it here.

Every time I create new projects in React or Openzepplin, I always have to install the huge node_modules for every projects. This consumes a lot of space and it takes quite a lot time to install.
So I thought about creating one global node_modules folder where all the create-react-app and openzepplin modules are located, and every time I create a new project, I link the required module from the project folder to the global modules folder. The global node_modules are stored in /usr/local/lib/node_modules/.

However, it did not work. What I did was that I created a symbolic link by using ln command. (
I searched online for help but I couldn’t find any article. I think it has to do something with configuration of package.json file or it may not support symbolic links.

package.json
{
  "name": "my first app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.12.0",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^12.8.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.1.2"
  },
  "scripts": {
    "start": "BROWSER='firefox' react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Error message
sh: react-scripts: command not found

If anyone has any idea how to make global node_modules, I would like to know.
It could be completely different way.

Hi,

Having global node_modules is highly discouraged because it always leads to complications when running different projects from the same node_module base. Even though it takes a lot of space and time, it is always recommended to have a local node_module for every project.

You do not want to mess up dependencies from one project to another especially when working on production level code. It takes a lot of time and effort to resolve issues that sprout up because of dependency problems.

Hope this gives you a perspective.

Happy Learning! :slight_smile:

1 Like

So I shouldn’t use (try to create) global node_modules then.
Thank you for the detailed reply!!

1 Like