lerna: Running lerna bootstrap does not install all dependencies

Expected Behavior

When running lerna bootstrap all dependencies should be install in packages.

Current Behavior

If I run lerna bootstrap and then run lerna start to start all my clients and packages, I get the following error:

@raisalholdings/raisal-ui:    2263 modules
@raisalholdings/raisal-ui: ERROR in ../raisal-utils/src/reduxUtils.js
@raisalholdings/raisal-ui: Module not found: Error: Can't resolve 'redux-actions' in '/Users/scott/Develop/Raisal/2.0/raisal-clients/packages/raisal-utils/src'
@raisalholdings/raisal-ui: ERROR in ../raisal-utils/src/reduxUtils.js
@raisalholdings/raisal-ui: Module not found: Error: Can't resolve 'redux-optimistic-ui' in '/Users/scott/Develop/Raisal/2.0/raisal-clients/packages/raisal-utils/src'

If I cd into packages/raisal-ui, and run yarn, I get the following error:

error An unexpected error occurred: "ENOENT: no such file or directory, lstat '/Users/scott/Develop/Raisal/2.0/raisal-clients/packages/raisal-ui/node_modules/@raisalholdings/raisal-utils/node_modules/history/node_modules'".
...

But if I run yarn one more time, everything installs in raisal-ui and I can then run lerna run start and everything starts fine.

Possible Solution

Install all deps or provide logs to debug

I have the following setup:

root/
  clients/
  packages/
  lerna.json
  package.json

lerna.json

{
  "lerna": "2.5.1",
  "packages": [
    "clients/*",
    "packages/*"
  ],
  "npmClient": "yarn",
  "version": "2.1.13"
}

Your Environment

Executable Version
lerna --version 2.5.1
npm --version 6.0.0
yarn --version 1.6.0
node --version v8.9.3
OS Version
Sierra 10.13.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 94
  • Comments: 66 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Thanks @scottmcpherson! I also came to this simple workaround:

// package.json
{
  "scripts": {
    "bootstrap": "lerna exec npm install",
    "publish": "lerna publish --force-publish",
    "test": "lerna run test"
  },
  "devDependencies": {
    "lerna": "3.0.0-beta.21"
  }
}

So the lerna exec npm install command does the trick.

This problem was fixed for our project by changing our “packages” path to include two asterisks instead of one. I just happened to get lucky on this one:

{
  "packages": [
    "modules/**"
  ],
  "version": "1.0.0"
}

UPDATE: spoke a little too soon I guess, I get different results with successive runs of lerna bootstrap. The first run will install all deps for packages A and B, but not C and D. The second run will install all packages for A and D, but not B and C. It changes on every run. Running lerna link && lerna exec npm install seems to do the trick for now. Still investigating.

Same here with lerna 4.0.0

so… is there any solution for this problem? 😢

Still going on 😦

This is still happening - any solution?

Problem still exist on Lerna 5.1.8.

I tried the workaround butlerna exec -- npm installignores .npmrc file which is at root level

We can’t believe in the continuation of such a bug

Although lerna exec npm install works fine. This problem still exist on lerna@3.22.1

Repro

I created a Docker container with instructions how to reproduce the issue: silvenon/lerna-bootstrap-issue. You can check out the failing (lerna bootstrap) vs successful (lerna exec yarn && lerna link) script.

@xpepermint What ended up working for us was creating a custom js bootstrap script and executing that using yarn bootstrap.

The script is scripts/bootstrap.js:

const spawnSync = require('child_process').spawnSync
const fs = require('fs-extra')
const path = require('path')
const chalk = require('chalk')

const RAISAL_UI_DIR = path.join(process.cwd(), 'packages', 'raisal-ui')

if (!fs.existsSync(RAISAL_UI_DIR)) {
  console.log(chalk.red(`Trying to find: ${RAISAL_UI_DIR}`))
  return console.log(
    chalk.red('Yarn bootstrap must be run from root of project')
  )
}
spawnSync('lerna', ['bootstrap'], {
  stdio: 'inherit'
})
spawnSync(/^win/.test(process.platform) ? 'yarn.cmd' : 'yarn', ['install'], {
  cwd: RAISAL_UI_DIR,
  stdio: 'inherit'
})
spawnSync(/^win/.test(process.platform) ? 'yarn.cmd' : 'yarn', ['install'], {
  cwd: RAISAL_UI_DIR,
  stdio: 'inherit'
})

Replace const RAISAL_UI_DIR = path.join(process.cwd(), 'packages', 'raisal-ui') with the dir that needs the packages reinstalled.

And then in my root package.json I added an npm script:

"scripts": {
    "start": "lerna run start --stream --parallel",
    "bootstrap": "node scripts/bootstrap.js",
    ...

Same issues for us. Banging my head against a wall. Works fine on my Mac. Causing me issues on remote Ubuntu server or in a docker container.

I literally can’t debug without an actual reproduction. Telling me what your tree looks like is worthless without the actual contents of the package.json files.

For me, lerna bootstrap --hoist worked fine on my dev machine, but in my client’s facility it would only install top-level dependencies. Upgrading that system from Node 14.x to 16.x solved the problem.

I had the same issue and the root cause was that some packages were not listed in the root package.json file (probably because they were not added using npx lerna add but manually). All packages in a monorepo should be listed in root package.json file:

// root package.json
{
  (...)
  "dependencies": {
    "@repo/package-name": "file:packages/package-name",
    (...)
  }
}

In case you want devDependencies to be installed, you have to make sure that NODE_ENV is not “production”

I ran into this when transitioning from workspaces and yarn -> npm@6. With yarn, I originally had useWorkspaces set to true in my lerna.json, which I believe tells lerna to just defer to yarn for installing and hoisting. When I removed that, lerna properly installed externals for all packages as intended.

TL;DR: It was my fault. Make sure useWorkspaces in lerna.json is not set to true when using npm as your npm client.

This is actually the exact issue: https://github.com/lerna/lerna/issues/1457#issuecomment-812293323

I globally set NODE_ENV as production in the CI runner and it literally messed up everything

Any ideea why I started receiving this error ?

lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in ‘@pu/event-listeners’ lerna ERR! yarn install --mutex network:42424 --non-interactive stdout: lerna ERR! yarn install --mutex network:42424 --non-interactive stderr: error Package “” refers to a non-existing file ‘“D:\pu\packages\auth-service”’.

lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1 in ‘@pu/event-listeners’ lerna WARN complete Waiting for 3 child processes to exit. CTRL-C to exit immediately. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Facing the same issue with latest version of lerna…

14864 silly saveTree -- ssf@0.10.2 14864 silly saveTree – frac@1.1.2 14865 warn onlinewebapp@1.0.0 No repository field. 14866 verbose stack RangeError: Maximum call stack size exceeded 14866 verbose stack at RegExp.test (<anonymous>) 14866 verbose stack at isDepOptional (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:428:45) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:437:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14866 verbose stack at failedDependency (C:\Program Files\nodejs\node_modules\npm\lib\install\deps.js:453:9) 14867 verbose cwd D:\BranchWebApp\branchwebapp\packages\onlinewebapp 14868 verbose Windows_NT 10.0.18362 14869 verbose argv “C:\Program Files\nodejs\node.exe” “C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js” “install” “–global-style” 14870 verbose node v12.16.3 14871 verbose npm v6.14.4 14872 error Maximum call stack size exceeded 14873 verbose exit [ 1, true ]

@ericsvendsen solution worked, thank you!

For me, lerna bootstrap --hoist worked fine on my dev machine, but in my client’s facility it would only install top-level dependencies. Upgrading that system from Node 14.x to 16.x solved the problem.

I ended up adding a postinstall bootstrap script to the root’s package.json as follows:

"scripts": {
    ...
    "bootstrap": "lerna bootstrap && lerna exec npm install",
    ...
}

This way, I get to do my normal npm install and once it finishes, I will execute npm run bootstrap, which in turn will execute the lerna bootstrapping along with installing all my dependencies in all of my packages.

NOTE: Making this to be in the postinstall lifecycle script was not a good idea because when someone installs the dependency it will execute the postinstall script, and will cause errors

@ktalebian I had the same issue… what i end up doing is:

npx lerna bootstrap --force-local --hoist --ci -- --production=false

–hoist will install all external dependencies in the root node_modules and then i used root node_modules packages in all my sub packages package.json -> scripts section. For example from one sub package script i did:

"test": "node ../../node_modules/jest/bin/jest.js"

Adding

  "workspaces": {
    "nohoist": [
      "**"
    ]
  }

to one of our package create the problem for us

I ran into the same problem today as well. Got more or less the same error message. In my case it was the a mistake on my side – obviously 😆

I have created a new package:

mkdir new-package && cd new-package
yarn init -y

Then I added this new package as a dependency to an already existing package:

existing-package/package.json:

{
   "dependencies": {
      "new-package": "^0.1.0"
   }
}

However, new-package was created with version 1.0.0. Thus lerna bootstrap was not able to find it.

In my case adjusting the version number fixed the issue. Not sure if this is the root cause in your specific case…

~Can we please reopen? It really does not install package dependencies on Ubuntu. Using npm after lerna link convert. lerna exec -- npm install works fine. Is this by design?~

It works now, but I cannot remember specifically what I did to resolve this. Since I was migrating from yarn, I had to remove the workspaces reference from my package.json - After that, I tried with a fresh clone and it seemed to work.

My issue seems the same, quite hard to share. B depends on A.

  • packages
    • A - all is fine
    • B - not fine, A dependencies are not installed

Doing lerna exec -- npm i && lerna link does what I want. From bootstrap description

  1. npm install all external dependencies of each package.

@evocateur does this mean that the external dependencies of the linked packages will not be installed? Edit: I’m not hoisting.