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] [Yarn] Should package lockfiles be committed when using yarn?

See original GitHub issue

Context

Setting up a greenfield project with yarn + lerna for the first time. Seeing high churn in yarn.lock files across different developers’ machines.

We’re unsure if we should be committing yarn.lock files in each of our packages/ directories, or ignore them as we wouldn’t be shrinkwrapping with npm.

Your Environment

Multiple developer machines, either OS X 10.11/10.12 or Ubuntu

Executable Version
lerna --version 2.0.0-rc.4
npm --version 3.10.8
yarn --version 0.23.4
node --version v6.9.1
OS Version
macOS Sierra 10.12.3

Looking for guidance/recommendation on committing or ignoring yarn.lock files in packages/. While yarn’s guidance on lockfiles is that they should be committed, I’m wondering if the same advice applies when using lerna to manage multiple packages.

We’re in the early stages of setting up a monorepo with lerna for a universal app and most (if not all) dependencies are listed in both the project root (for the web server) and duplicated in each package’s package.json.

Using npm@3 in a monorepo, I would usually use a shrinkwrap to lock down versions in the app and let packages embrace semver. Unfortunately, I’m not sure if or how the switch to yarn changes best practices here.

It’s early on, so I’m tempted to YOLO and learn from our mistakes, but I’m seeing a bunch of churn in yarn.lock files across different developers’ machines–along the lines that I would normally expect with a freshly generated shrinkwrap in npm@2 😢.

I looked around in issues and docs, but I couldn’t find any guidance. Likewise, if there are resources elsewhere that I can use, I’m happy to ask questions elsewhere 😃

If anyone’s able to share what they consider to be best practices working with yarn and lerna (and why), I’d be both grateful and an imminent docs contributor.

Thanks in advance… you’re doing some great work here!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
evocateurcommented, May 19, 2017

…[Most] (if not all) dependencies are listed in both the project root […] and duplicated in each package’s package.json.

Have you tried --hoist yet? It sounds like you’re pretty close to the ideal pattern for hoisting already. If everything gets hoisted, no lockfiles will be generated in the packages/* directories, and the root lockfile becomes the single source of truth.

Personally, I do exactly that: yarn.lock in the root, command.bootstrap.hoist = true in lerna.json, and the only thing that happens in packages/* during lerna bootstrap execution is symlinking and running prepublish. (Granted, I’m not using --npm-client=yarn, but same diff in this case)

Unfortunately, there is currently no automated way to “synchronize” hoisted package versions, so whenever you update a version in the root, you’ll have to manually bump the matching package versions under packages/*/package.json (it will warn you of a mismatch during the next lerna bootstrap if you don’t sync). It’s something I’d like to get around to at some point, though given the length of my todo list, it probably won’t get done any time soon…

0reactions
lock[bot]commented, Dec 27, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should I commit yarn.lock and package-lock.json files?
Whether you choose to commit yarn.lock or package-lock.json or both depends on whether those developing on your project are only using Yarn or ......
Read more >
Stop using package-lock.json or yarn.lock | by Gajus Kuizinas
Official NPM documentation encourages to commit package-lock.json files to the source code version control: It is highly recommended you commit the generated ...
Read more >
The Ultimate Guide to yarn.lock Lockfiles - Andrew Hansen
Every project using yarn should commit the yarn lockfile to source control. The lockfile is the source of truth for telling other developers ......
Read more >
Yarn lock: how it works and what you risk without maintaining ...
lock file is generated. It lists the versions of dependencies that are used at the time of the installation process. That means it...
Read more >
Lockfiles should be committed on all projects | Yarn Blog
Yarn needs this info about every dependency because packages are constantly changing. New versions of packages are published all the time and ...
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