Question: how to generate package-lock.json per-package when switching to npm
See original GitHub issueWe have a Lerna mono-repo in a structure such as:
/
/packages
/package1
/package2
/package3
...
We currently use Yarn, but would like to switch back to npm.
We have a yarn.lock
file at the root of our mono-repo, but do not have per-package yarn.lock
files since we never enabled Workspaces. When moving to npm, we would like to ensure that we have per-package package-lock.json
files, which properly mark devDependencies with "dev": true
.
I have not been able to find a way to generate these files.
What I’ve tried:
Attempt: npm run lerna boostrap --hoist
Outcome: package-lock.json
generated at the top-level only (maybe this is expected due to the --hoist
?), but, with no "dev": true
tags. Also, it includes no local packages (again, not sure if this is expected or not).
Attempt: cd packages/package1 && npm install
Outcome: install fails because npm
does not know how to find a local package
Attempt: npm run lerna add express --scope=package1
Note: package1
already has express
in its package.json
Outcome: package-lock.json
files are added for all packages except package1
. Further, these files do not mark devDependencies with "dev": true
, and, do not include local packages (which I assume they should, but correct me if I’m wrong about that)
I was expecting that when I ran npm run lerna boostrap --hoist
it would generate the per-package package-lock.json
files for me.
How can I generate these files (correctly), or is the single top-level one generate by the bootstrap
command correct? If so, how can I get it to properly tag things with "dev": true
, and include local dependencies?
Meta info: Node version: 8.11.1 npm version: 6.1.0 Lerna version: 2.11.0
lerna.json
{
"lerna": "2.11.0",
"npmClient": "npm",
"packages": [
"packages/*"
],
"version": "0.0.0"
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:22
- Comments:39 (9 by maintainers)
I couldn’t find a concrete solution to generate lock files for all packages. I mean there are ways but, everything is increasing the installing time to very high. Below are 2 ways to generate package-lock.json file for all packages:-
As above 2 solutions were taking way to much time hence i could not use any of them for my scenario hence, i came up with a third way or i would call it a workaround , this is also not the cleanest solution but does the job with very slight increase in installation time.
Create a npm script in all your packages which would generate only package-lock file without installation which would be something like below:-
"genPackagelock": "npm i --package-lock-only"
In you root package.json file as part of postinstall call the above defined script for all the packages as below:-
"postinstall": "lerna run --parallel genPackagelock"
The above “postinstall” basically generates package-lock.json file for all the packages along with the internal dependencies.
I am not closing the Bug because the above solutions are a workaround and not one of the best solution.
@tivac - Any thought on above proposal.?
Using
lerna@3.0.0-beta.21
package-lock is not generating per (nested) package when usingnpx lerna bootstrap
Have also tried
npx lerna exec -- npm i
, and tried using alsolerna@2.11.0
andlerna@2.9.0
None of these work.
Lerna project current looks like this:
Lerna.json
If I manually
cd
to each package andnpm i
then it works, it goes without saying that this is an undesirable workflow.