NPM 7 Workspaces - Multiple node_modules?
Asked Answered
B

1

4

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

Bromate answered 14/7, 2021 at 17:1 Comment(0)
B
4

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!

Bromate answered 15/7, 2021 at 16:46 Comment(2)
Have solved this issue with just updating npm and node version? Because in my example I see node_modules in packages but its contains only small subset of all dependencies.Vinnievinnitsa
@Vinnievinnitsa I'm not sure I understand what you mean, sorry!Bromate

© 2022 - 2024 — McMap. All rights reserved.