Individual package-lock.json for npm workspaces

1.3k Views Asked by At

I have two packages inside my npm workspace api & cdk. I would like to create an individual package-lock.json inside api & cdk as both of those projects will get deployed individually. Is this currently possible with npm workspaces? What are other alternatives or strategies?

├── api
│    ├── package.json
├── cdk
│   ├── package.json
├── node_modules
├── package.json
├── package-lock.json 
1

There are 1 best solutions below

0
On

No, a package-lock.json file will not be generated during npm install for workspaces. This is because workspaces allow for mutual dependencies to be shared.

To handle your CI/CD process, you should use the root package-lock.json and package.json files for each workspace.

Personally, I would suggest creating a root builder Dockerfile that installs all the dependencies. Each workspace's Dockerfile can then copy the dependencies from the root builder.