Sharing dependency version with NPM workspaces in monorepo

35 views Asked by At

We switched to NPM workspaces to share source code. Works fine.

We want to go further and utilize NPM workspaces to share dependencies. Like every WEB app in monorepo should be built with Next.js v14.0.3 - not any other version.

How could we achieve version sharing?

1

There are 1 answers

0
gavenkoa On

Seems we are able to define a workspace with empty index.js solely for the purpose of defining a dependency list, to consume it transitively:

{
  "name": "@corp/static-nextjs-site",
  "version": "0.0.1",
  "dependencies": {
    "express": "^4.18.3",
    "http-proxy-middleware": "^2.0.6",
    "morgan": "^1.10.0"
  }
}

and then include it into other submodules (workspaces):

  "dependencies": {
    "@corp/static-nextjs-site": "^0.0.1",
    ...

This way it is possible to share version specification in workspace managed mono-repo.