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.

[Question] Calling devDependencies with CLIs after `lerna link convert`

See original GitHub issue

I was running into problems getting a new leaf package to install, and decided to move all devDependencies up to the root package to get around the problem. One leaf package is a Vue web app, and can no longer build as “webpack” no longer exists in node_modules/.bin. I feel like I must be doing something wrong as this seems like it would break a lot of projects.

From npm:

sh: webpack-dev-server: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! yourdata@0.1.0 dev: `webpack-dev-server --config build/webpack.dev.conf.js`
npm ERR! spawn ENOENT
…

Edit: On another note, is there a better place for questions? IRC? Discord? Gitter?

Expected Behaviour

Using lerna link convert for the benefits it offers doesn’t break npm scripts in leaf packages.

Current Behaviour

It appears to do so.

Possible Solution

Lerna symlinks /packages/<leaf package>/node_modules/.bin to /node_modules/.bin. This worked for me, so I’ll create a script to perform this step in CI.

Manual Solution

This should work if all of your leaf packages are rooted two directories below the monorepo root, as is usual. It’ll probably spit out some mkdir or rm errors, but it will carry on.

lerna exec "rm -r node_modules/.bin ; mkdir node_modules ; ln -s ../../../node_modules/.bin node_modules/.bin"

Steps to Reproduce (for bugs)

  1. Install webpack-cli as a devDependency of a leaf package.
  2. Run lerna link convert. This will remove the devDependency from the leaf package and add it to the root package.
  3. Attempt to use webpack in a leaf package script.
lerna.json

{
  "packages": [
    "packages/*",
    "sites/*"
  ],
  "version": "0.1.0"
}

Environment

Executable Version
lerna --version 3.10.7
npm --version 6.9.0
yarn --version n/a
node --version 11.6.0
OS Version
macOS High Sierra 10.13.6

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
bliequecommented, Jun 5, 2019

@clark-stevenson I’ve been where you are. I have a script on the root package which will give you the behaviour you want. It’s not the cleanest solution, but it does work. If your leaf packages have production dependencies, though, it may cause problems.

"scripts": {
  ...
  "symlink-bins": "lerna exec \"rm -r node_modules/.bin ; mkdir node_modules ; ln -s ../../../node_modules/.bin node_modules/.bin\""
},

npm run symlink-bins in the root will then set up symlinks for webpack-dev-server and other CLIs.

2reactions
evocateurcommented, Jun 6, 2019

This is actually something pnpm recursive handles out of the box. Considering switching myself given the likelihood that workspaces aren’t coming to npm any time soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding lerna into monorepo project | by Morty Green - Medium
Lerna hold hoisted devDependencies there(check chapter common devDependencies in lerna doc). Use lerna link convert command to “extract” ...
Read more >
Dependencies vs devDependencies in monorepo
A couple caveats: This only works for non-CLI devDependencies . If you need to run a CLI from a child package, that CLI...
Read more >
FAQ | Lerna
Frequently asked questions. This document is a work in progress. How do I add a package to my Lerna repository?​. For any packages...
Read more >
Managing multiples projects with Lerna and Yarn Workspaces
If a package has a dependency on other package in the workspace, they are linked without affecting your global environment. Since Yarn 1.0,...
Read more >
@lerna/list | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
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