DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Ermal Shuli
Ermal Shuli

Posted on

Is it possible to share npm packages between multiple projects

I'm playing with react, trying to create many mini apps exploring different react feature. Creating a new react project and installing the same packages over and over again seems to be too much.

Is there a way to reuse the same node modules for a different project? This is what I think I want

/node_modules
/project1
  - package.json - where I run npm start from
/project2
  - package.json - where I run npm start from
/project3
  - package.json - where I run npm start from

From my google research, I've tried having this on every package.json but it doesn't work

  "scripts": {
    "dev": "NODE_PATH=$HOME/to/my/parent/folder/node_modules/",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Is there a way to do it?

Top comments (4)

Collapse
 
dmfay profile image
Dian Fay

Look into lerna.

Collapse
 
ermal profile image
Ermal Shuli Author • Edited on

I will thanks

Apparently though, when I ran npm run eject on the created react application it solved the problem

It be cool if lerna fixes this issue without ejecting. I'll try it

Collapse
 
vishwarajanand profile image
Vishwaraj Anand

I didn't try but probably you can put a symlink to another node project's node_modules/someModule in your own project?

Collapse
 
tobiassn profile image
Tobias SN

I think you should just have a single app that’s separated into different parts, one for each experiment.

🌚 Life is too short to browse without dark mode