question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to update dependencies in sub-packages

See original GitHub issue

Expected Behavior

DevDependencies can be shared amongst the root package and sub-packages. For example, it’s nice to be able to run tests in a specific package and at the root directory. This mean all packages (including root) share the same test runner. Lerna is able to hoist shared dependencies to the top (which is nice).

However, when updating shared dependencies offer no help to bump version in all packages. Of course I can use lerna exec -- npm update whatever, but NPM will actually install the new version in each packages which can take forever.

Possible Solution

A command like lerna update could run over every package.json and match the version with the root. Alternatively, in order to not rely in the root package, lerna update whatever@X.X.X could be used to define the required version.

Steps to Reproduce (for bugs)

  1. Have a lot of sub-packages with outdated dependencies
  2. Be using lerna bootstrap --hoist
  3. Wish to update all sub-packages

Context

All my sub-packages and root share AVA, nyc and esm. It means I can run npm test in the root to test everything (in CI for example) or in any sub-directory (while adding a new feature for example). Updating these dependencies can turn into a nightmare. Running lerna exec -- npm update ava nyc esm take way too long and moreover actually install the package when I just want to update the package.json. Copy-pasting the version to all package.json and running lerna bootstrap --hoist is viable, but as the number of sub-packages grows it becomes more and more tedious.

Your Environment

Executable Version
lerna --version 3.15.0
npm --version 6.7.0
node --version 11.13.0
OS Version
Windows 10 1803

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:60
  • Comments:19

github_iconTop GitHub Comments

13reactions
leifoolsencommented, Aug 29, 2019

That would be a nice feature. But as a workaround you could use e.g. syncpack

Example: update React from version 16.8.6 to 16.9.0.

npm outdated

react                16.8.6  16.9.0
react-dom            16.8.6. 16.9.0

Open package.json at project root and set the new versions.

  "devDependencies": {
    "@babel/cli": "7.5.5",
    "@babel/core": "7.5.5",
    ...
    "react": "16.9.0",
    "react-dom": "16.9.0",
    ...
    "webpack": "4.39.2"
  },

Open one of the sub projectes (in ./packages) that have these dependencies and set the new versions here as well.

  "peerDependencies": {
    "classnames": "^2.2.6",
    "prop-types": "^15.7.2",
    "react": "^16.9.0",
    "react-dom": "^16.9.0"
  },

Save and run npx syncpack list --peer from project root to verify that changes are detcted.

Run npx syncpack fix-mismatches --peer to upgrade similar dependencies in all the other subprojects.

syncpack-fix-mismatches

BTW: We use peerDependencies for all third party packages and dependencies for our internal packages:

{
  "name": "@brreg-frontend/button-react",
  "version": "0.0.96",
  "main": "lib/index.js",
  "author": {
    "name": "UX team",
    "url": "https://www.brreg.no/"
  },
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "....."
  },
  "publishConfig": {
    "access": "public"
  },
  "files": [
    "lib/",
    "src/"
  ],
  "peerDependencies": {
    "classnames": "^2.2.6",
    "prop-types": "^15.7.2",
    "react": "^16.9.0",
    "react-dom": "^16.9.0"
  },
  "dependencies": {
    "@brreg-frontend/button-style": "^0.0.72",
    "@brreg-frontend/icon-react": "^0.0.75"
  }
}
10reactions
sprilukincommented, Oct 8, 2020

I started using lerna to be able to install all node modules for all subpackages using single command. At the moment i do not use any other lerna features except lerna bootstrap. My lerna.json:

{
  "lerna": "3.22.0",
  "npmClient": "yarn",
  "packages": [
    "package-a",
    "package-b"
  ],
  "version": "1.0.0"
}

my root package.json:

{
  "name": "test",
  "private": true,
  "version": "1.0.0",
  "scripts": {
    "postinstall": "lerna bootstrap"
  },
  "dependencies": {
    "lerna": "^3.22.1"
  }
}

my package-a’s package.json:

{
  "name": "package-a",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "moment": "2.22.0"
  }
}

my package-b’s package.json:

{
  "name": "package-b",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "package-a": "1.0.0",
    "moment": "2.22.0"
  }
}

i want to upgrade moment in the package-b. if i run yarn upgrade moment --latest in the package-b folder i got the following error:

yarn upgrade v1.22.5
[1/4] 🔍  Resolving packages...
error Received malformed response from registry for "package-a". The registry may be down.
info Visit https://yarnpkg.com/en/docs/cli/upgrade for documentation about this command.

if i run npx lerna --scope package-b exec -- "yarn upgrade moment --latest" in the root folder i get the following error:

lerna notice cli v3.22.1
lerna notice filter including "package-b"
lerna info filter [ 'package-b' ]
lerna info Executing command in 1 package: "yarn upgrade moment --latest"
yarn upgrade v1.22.5
[1/4] 🔍  Resolving packages...
error Received malformed response from registry for "package-a". The registry may be down.
info Visit https://yarnpkg.com/en/docs/cli/upgrade for documentation about this command.
lerna ERR! yarn upgrade moment --latest exited 1 in 'package-b'
lerna ERR! yarn upgrade moment --latest exited 1 in 'package-b'

How should i properly upgrade mode module in the lerna’s sub-package?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to upgrade node module of the lerna's subpackage
json file. Now run: cd package-b && yarn upgrade moment --latest && cd .. Then put the "package-a": "1.0.
Read more >
HOW TO: Update all npm packages in your project at once
Once updated, you can then revert to using the npm update command as you are now up to date. That node script? wipe-dependencies.js?...
Read more >
Managing Dependencies - UiPath Documentation Portal
Simultaneously, the versions of dependencies are updated in the project.json file belonging to the project. To add dependencies to a project, simply search...
Read more >
Selective dependency resolutions - Yarn
You may be depending on a package that is not updated frequently, which depends on another package that got an important upgrade. In...
Read more >
Fedora Packaging Guidelines
In this case one or both SHOULD be packaged in subpackages in order to allow other ... dependencies on package names require unnecessary...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found