Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM 7 Workspaces - Multiple node_modules?

I'm having trouble running my app with NPM 7 Workspaces. I am expecting an npm install from the root folder to create a node_modules folder for each of my workspaces, similar to Lerna. However, when I run npm install at the root, I only get one node_modules, at the root level. Is this expected?

Example structure before npm i:

.
├── package.json ->  { "workspaces": ["packages/*"] }
└── packages
    ├── a
    │   ├── index.js
    │   └── package.json
    ├── b
    │   ├── index.js
    │   └── package.json
    └── c
        ├── index.js
        └── package.json

Example structure after npm i (note only one package-lock.json/node_modules):

.
├── package.json ->  { "workspaces": ["packages/*"] }
├── **node_modules**
├── **package-lock.json**
└── packages
    ├── a
    │   ├── index.js
    │   └── package.json
    ├── b
    │   ├── index.js
    │   └── package.json
    └── c
        ├── index.js
        └── package.json

Node version: 16.4.2

NPM version: 7.18.1

like image 905
ailish Avatar asked Sep 01 '25 10:09

ailish


1 Answers

Update: After messing around a with a million things, I finally went and deleted the project and recloned it. It worked after this. I believe it was due to the fact that I was on an old node/npm version when I originally cloned the project. Must have been some funky state lingering around there. Anyway hope this helps anyone with the same problem!

like image 105
ailish Avatar answered Sep 04 '25 05:09

ailish