[Question] Calling devDependencies with CLIs after `lerna link convert`
See original GitHub issueI 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)
- Install webpack-cli as a devDependency of a leaf package.
- Run
lerna link convert
. This will remove the devDependency from the leaf package and add it to the root package. - 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:
- Created 4 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top GitHub Comments
@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.
npm run symlink-bins
in the root will then set up symlinks for webpack-dev-server and other CLIs.This is actually something
pnpm recursive
handles out of the box. Considering switching myself given the likelihood that workspaces aren’t coming tonpm
any time soon.