3

I started using lerna to be able to install all node modules for all sub packages using a 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 node module in the lerna's sub-package?

hong4rc
  • 3,999
  • 4
  • 21
  • 40
SergeyP
  • 429
  • 5
  • 8
  • 1
    there are couple related issues opened in their's github: https://github.com/lerna/lerna/issues/2142 https://github.com/yarnpkg/yarn/issues/6652 https://github.com/lerna/lerna/issues/2477 but no working answers for my problem so far – SergeyP Oct 08 '20 at 15:51

1 Answers1

3

Because both of your packages are private the npm repository can't find them during the upgrade of the moment library. Also the lerna package is currently largely unmaintained.

There exists a workaround. Temporally delete the "package-a": "1.0.0", line from your package-b.json file.

Updated package-b/package.json file:

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

Now run:

cd package-b && yarn upgrade moment --latest && cd ..

Then put the "package-a": "1.0.0", line back to your package-b.json file.

a1300
  • 2,633
  • 2
  • 14
  • 18
  • Thank you, I found this workaround. My hope was that i misunderstood something about how to use lerna. Is there any suggestion what can i use instead of lerna? i know about yarn workspaces but workspaces uses some special hoisting technique so my project is not working. – SergeyP Oct 23 '20 at 14:44
  • There are alternatives to lerna. But maybe lerna can do it also. What are you trying to accomplish? Do you want to publish your packages in the future? – a1300 Oct 24 '20 at 06:42
  • no my packages are intended to be private, no publishing is planned. Again - i need lerna only to automatically install node modules in all subpackages in topological order. I do not need other lerna capabilities (except maybe lerna run which allows me to run any npm script in any/all subpackages) – SergeyP Oct 24 '20 at 08:51
  • 1
    [rushstack](https://github.com/microsoft/rushstack) is a good alternative to lerna. It is also maintained :) You mentioned that yarn workspaces aren't working for you. Thats a shame, because they are pretty easy to deal with. `yarn workspaces` are installing all packages under `node_modules` and symlink them. See this [example](https://stackoverflow.com/a/58238213/5536304) (yarn workspaces with typescript, can be also used without typescript) – a1300 Oct 24 '20 at 09:43
  • @SergeyP did my answer answered your question? If yes, please accept it. https://stackoverflow.com/help/someone-answers – a1300 Oct 25 '20 at 09:05
  • I know how to use yarn workspaces. It simply does not work because by default it hoist all node_modules to the root and some of the 3rd party deps does not like this because after this my build process is completely broken - a lot of different errors. There is a `nohoist` option which allow to keep all node_module in each subpackages. But there is a problem with dependency resolution - after running yarn install yarn did wrong symlink of the semver binary (there are different versions of semver used by different 3rd party libs). Thas't why it does not working for my setup. – SergeyP Oct 27 '20 at 13:52
  • @SergeyP that sounds like a bug. Maybe [rushstack](https://github.com/microsoft/rushstack) will work for you – a1300 Oct 27 '20 at 14:44