Yarn 3.0
github.com
github.com
The fastest are usually either Yarn PnP or pnpm. Note however that regardless of the package managers it's quite clear that performances are reaching a plateau in the common cases. I personally believe a better thing to consider are feature set, stability, documentation, and general codebase health (since it impacts how fast features and bugfixes ship, and how dangerous upgrades may be). But those are quite a bit harder to measure, of course!
I didn't look into it since Yarn was released.
I always thought it was weird that npm didnt use a central store on your hard drive for your packages and instead just duplicated them everywhere, and i always thought it was even weirder that yarn didn't change this behaviour, but maybe i'm missing something.
So now a project has to explicitly opt-in to Yarn pnp.
The reason for that is that PnP tends to require recent versions of some of your dependencies, so migrating to it can be somewhat involved, and it's better experience to let you keep using the install strategy you're used to until you decide to change it yourself.
New projects, on the other hand, already use the latest versions from their dependencies, so it's a much better starting point for PnP.
Probably any package that ships assets (static files) and uses file I/O to read instead of require()
1. https://pnpm.io/blog/2020/05/27/flat-node-modules-is-not-the...
You can override any version of a package anywhere in the dependency tree. For example, to resolve a CVE in one of your zillion packages.
pnpm has "hooks" which can do that and more, though I still prefer yarn resolutions.
A quick and lazy google search didn't yield a result...
Had anyone found significant benefits from switching to yarn 2? And conversely, has anyone had any issues with this?
EDIT: It seems that there is also a 3rd option: pnpm. Experiences with pnpm would also be welcomed.
The issues we had are with some packages who don’t list their peerDependencies correctly, or which assume the file structure of node_modules will be the one made by npm. But yarn has improved and these obstacles are much easier now.
I don't understand why npm just can't improve perf. Seems fixable. In my smaller personal projects without as many dependencies, I just use npm and it's easier.
After performance, the other main reason we moved from npm to yarn was exactly that it completely removed an entire class of bugs we had that were caused by incompatible packages versions installed in various places of the repo.
In exchange of that, yarn will warn if it encounters packages that don’t declare their reps and peerDeps correctly. And there are loads of those. if you want to be safe and remove these warnings, you will have to either ask the package authors to declare their depa correctly, or fix them yourself manually in your yarn YML file.
Ask your team the question: what's the difference between npm update, npm install, npm update --workspaces, npm install --workspaces, and how the outcome differs between npm versions.
Bonus points for knowing in which scenario package-lock.json is taken into account.
If yarn is even worse, my last hope is gone. Please don't take that post too seriously :)
PHP's de facto package manager is Composer and it's very simple and clear in how it works:
Your composer.json states your dependencies and their version constraints.
Your composer.lock (also a json file) states the actual versions that should be installed, based off your composer.json.
"composer install" installs the exact versions from your composer.lock file, "composer update [package]" updates the lock file based on your constraints.
With npm this doesn't seem to be as straight-forward, sometimes I run "npm install" and the package-lock.json ends up changing, I definitely don't consider npm to be safe.
Because that is what I plan to do. Such a pain when some random dependency 50 packages deep is broken or even pulled from npm and so we can't even finish a deployment build until fixed. Especially for older projects.
So I am not sure it is better than npm, however, at least one does not have that split in package managers, which will additionally create friction in or between teams and projects.
This is intended behaviour, but seems totally counterintuitive to me. I’m with you, I’m used to Composer and NPM just seems inscrutable at times.
For reference, the approximate equivalent to `composer install` is `npm ci`. This will install the exact versions from package.lock without changing it, however it will also blow away your node_modules directory and install from scratch each time.
I never want the install command to change anything. I want it to install only.
Does Rome use yarn? Anyone using Rome in production?
Eg no Docker file in dev unless you need custome system dependencies. Otherwise alpine node in Docker compose and in prod Docker file
NPM 7 is fantastic, and feels like a worthy successor to Yarn 1. Yarn >=2 is probably fine for what it is, but I wasn't prepared to invest resources into rearchitecting how we handle dependencies for nebulous (or possibly negative) benefit. Meanwhile, the old release of Yarn 1.x that I'd pinned in order to work around a blocker regression (v1.21.1) was starting to show its age, and eventually became unusable after a third-party package update triggered another hidden blocker bug in that release (which, IIRC, the team had elected not to fix because only 1.x was affected). At that point, it was untenable for us to continue relying on a broken, unmaintained tool for such a critical function.
Luckily, the stable release of NPM 7 arrived just in time for us to switch over with minimal hassle. Performance and reliability have been notably better in my experience (keeping in mind that my baseline for comparison is a release of Yarn from two years ago).
I'm grateful to the Yarn project for pushing NPM in the right direction, and wish it and its remaining users all the success in the world, but I no longer see an urgent need in the ecosystem for Yarn to exist and would no longer recommend it by default for any greenfield project.
It was a fairly difficult migration, in particular because Yarn 2 PnP does not allow you to import a module that is not specified in package.json. Lots of libraries play fast and loose with dependencies, and so our .yarnrc.yml file which adds those missing dependencies is now 172 lines. PnP requires configuration for vscode and a custom build of TypeScript, which isn't ideal, but those have worked well.
I run about ~30 JS repos, ~10 of them monorepos. Since I migrated everything to yarn 2 its been a breeze, my other contributors have been able to completely forget about it (as it just works) and I've been able to assert that everything that works today will work in six months and two years.
That is because I have not gone against the default of 0-config repos, that is saving the .yarn/cache folder (equiv of node_modules) to git (via git-lfs). The lockfiles work. Dependencies can have conflicting dependent packages. I've had a small number of packages have issues with the zip format, which is solved by setting unplugged (very well documented).
A user clones the repo and they are done. Yarn itself is saved into the repo, so the only external dependency is nodejs.
Things I haven't thought about or done since switching to yarn 2:
* I don't worry that the server is running something different to the dev machine
* I don't get breakage because I switched branches
* I don't have to teach other people how to look after their packages (because it 'just works')
* I don't have to chase people to update when a lib we use has a vuln
* I don't spend time installing
* I don't care about package compatibility
Things I have had to worry about:
* build systems. When you use webpack, esbuild, etc. then they need a little help resolving packages
* in the beginning it was hard to step into dependencies. That is all fixed now.
* Sometimes a package is broken because they don't specify peerDependencies properly (which is a security & reliability issue), so you have to add to a config file (surprising first time, easy from then on).
Yarn is a big win.
- environment-independent lockfiles
- yes, you can have the same lockfile and run it behind different proxies with the same result now! very strong for corporate proxy situations with external dev teams
- pnp - superbly fast package install, gets faster as you use it more
Yarn 2 also has an upfront cost- all new config (yml)
- also renamed pretty much every property
- docs are decent and mitigate some of this
- doesn't come for free with node.js- conflicts with npm with regards to commands
- interacts awkwardly with npm config, leading to some situations where yarn installs fail due to npm config being partially and implicitly merged
Overall it's pretty good. Not really sure it's worth it unless install performance or multiple-proxy situations are present at your workplace though.
yarn.lock is _at least_ 15x smaller than an NPM lockfile. You want this committed into your repo, and I'd rather have ~200kb than 5mb.
So that's:
- Speed
- Artifact size
- Caching
- Proxy support
- Determinism (which has improved with NPM)
To me it was outrageous, that a tool used by so many could have such flaws. I stayed with npm, which also has the advantage of storing a more precise lock file than Yarn and I never had the same kind of issues as I had with Yarn. It seems more standard and safer than Yarn ever did, so I never bothered with upgrading Yarn.
I often need to work with a project, which has a big monorepo and chose to bundle its version of Yarn with that. Now it seems that there will forever be a Yarn version inside that project.
I have not noticed that much of a speed difference between npm and Yarn once things are cached and I value safety and correctness more than speed anyway, so that has not been a reason for me to try and make the switch either.
Second is a little more niche in running a Linux image on Windows host via Vagrant/Virtualbox. Out of the box symlinks won't work so bin files often fail. I would also run into file locks when running npm install on larger projects often, to the point where I was having to run it 5-10x before everything would finish installing. You can instruct Vagrant to offer some support (setextradata VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root 1), or set an environment variable to key on and update any scripts to use --no-bin-links, but it's flaky in my experience. I never found a solution to the file locks with npm.
I installed yarn on a whim on that setup and have yet to have any of those issues with it.
I can also add that the monorepo setup really makes it easy to manage project with multiple packages and interdependencies. You can have a look at our config for this here: https://github.com/lowdefy/lowdefy
For standalone projects there’s probably no benefit to be had.
`yarn config set enableTelemetry 0` per-project.
`yarn config set --home enableTelemetry 0` per-user.
After trying it on seldected projects, we collectively decided that it was not worth it to follow a project that did not take its users' time seriously, since the migration was so hard.
So, yarn@v1 then npm@v7+ for us.
Edit: I retract my previous comment, the additions/deletions count seems misleading.
I believe this is the greatest accomplishment of the v2.
I can’t believe npm still sucks after 10 years. Week doesn’t go by I have to nuke node_modules and occasionally the lock as well. It’s junk as far as I’m concerned, but I just happen to know what the problem is every time.
I am genuinely curious what are the specific issues which necessitate deleting all modules? Colleagues across operating systems with native modules? Old node versions?
Why? Because installing the dependencies they specify and running babel (implicitly at the latest version) does not have reproducible results. It's that simple. package-lock.json is specifically supposed to help with this, but in some cases, it just doesn't, and it's entirely possible, and common(!) to have two sets of package.json files produce differing package-lock.json files.
They even have a warning below that can still occur even if you already have the dependencies specified above installed:
> If you see an error message saying “You have mistakenly installed the babel package”, you might have missed the previous step. Perform it in the same folder, and then try again.
[1]: https://reactjs.org/docs/add-react-to-a-website.html
[2]: https://reactjs.org/docs/add-react-to-a-website.html#add-jsx...
Locally I just delete it and use yarn for all my commands, and they can use NPM for their commands.
It doesn't make much of a difference, not actually sure what the problem is.
Nobody would even know whether you're using yarn or NPM if you don't commit a lockfile I suppose
Just like no one would think of letting their developers choose whether they want to bundle their code using either Webpack or Rollup, the package manager should really be enforced at the project level, whether you choose Yarn or npm.
But I've been doing this for years and so far haven't ran into it
I really don't have the mental energy to fight with people over package managers -- it's just not worth it.
> your colleagues and you may have slightly different behaviors in development (on top of desync'd dependency trees).
Yarn and NPM both take a "package.json" and install the dependencies so that you can import them though.If I have "express" in my package.json and do "npm install" or "yarn install" -- the functional outcome is (and always should be) the same
Unless you're using some package-manager specific behavior so that it only works properly or relies on particularities from either yarn/npm/pnpm whatnot, I'm not sure I understand how this could cause problems
But also, you're the lead maintainer of Yarn and I'm just some schmuk who's been on the consuming end for the last many years. I reckon you've got a fair bit more clue here than I do.
Commit your lockfiles. Their whole point is to reduce the risk of dependencies silently breaking your build.
If you don't run tests in your production environment (and most people don't), then you need to commit a lockfile and use it when deploying.
I'm not surprised nor upset that V2 is radically different. It's all in the versioning scheme!
I see this as analogous to the Angular 2 situation, except that Google actually did a good job maintaining Angular 1 (retroactively named "Angular.js") for a number of years afterwards and providing a solid migration path. Everyone who had staked their projects and businesses on the future of Angular 1 was understandably annoyed.
All that being said, while I have problems with specifics of their approach, I actually think Yarn made the right call on this. After NPM caught up with v7, it became a bit of a wasted effort to have two redundant projects that were almost drop-in replacements for one another. Yarn staking out a different path at least justifies its continued existence.
What I think could have been better is if they'd put an explicit acknowledgement in the migration docs that Yarn 2 wasn't going to be a good fit for all users of Yarn 1, and a recommendation of NPM 7 as an alternative successor to Yarn 1 for such users. An even nicer gesture would have been if they'd written an alternate migration doc for Yarn 1 -> NPM 7.
If they'd made a new tool/project called "yarn2", leaving "yarn" alone, that would've been fine.
You install it into your repository, and it gets vendored.
The yarn 1 binary on your machine will use yarn 2/3 if it’s in the repo, otherwise it will just run yarn 1 as normal.
I spent some time trying to understand why I needed a third party plugin to run the equivalent of `yarn install --production` I just said fuck it and I'll let the frontend team figure this shit out.
So yeah, I wouldn't be surprised if the Yarn 1 usage is significantly higher than Yarn 2
Looked at Yarn 2, saw that it was a ton of work (compared to our npm -> yarn 1 transition) and said sod it.
Let's see if Yarn 1 -> 3 is any easier.
We did make an attempt at moving to Yarn 2, it did not work out well. At that time (probably 12 months ago or more) lots of upstream packages had broken package.json files, we never managed to fix them all. Lots of things with React were a bit screwy too!
I'm really glad for all the forward thinking projects like yarn and pnpm are bringing to the node package management space, and I'm also glad to see that npm is listening and taking those advancements into consideration. I'm currently exploring using npm v7's workspaces feature, which was something I originally wanted to use yarn for.
Once npm implements their recently-accepted overrides RFC, we're eager to try switching to that.
Is there any migration work needed to use v3 on a project bootstrapped with v1 or is it transparent?
Still sucks then.
I've wasted time twice now trying to move projects to Yarn 2 just to have the tsserver LSP break every time, being unable to find the packages despite following the documentation to the letter.
Every single time I've tried Yarn 2 I end up frustrated.
- Somehow one of our dependencies fail to install with old version of npm.
- Updating npm to last version fixes this, but on some machines, npm install fails with a 401 error despite having no private registries configured.
Still no fixes for this bug after multiples months:
- https://github.com/npm/cli/issues/2799
- https://github.com/npm/cli/issues/3284
- There is a lot of other issues on this.
Before this, whe had multiples other issues with npm (thats may be still live):
- npm is not extensible enough and require a lot of workarounds to be used in safely CI.
- There are bugs thats are not fixed for 2 years that make npm ci not working. (https://github.com/npm/cli/issues/289)
- All bug reports have been closed after a new version release because they have no idea if they fixed a bug or not.
Sadly, I can't use NPM v7 or Yarn yet :(
Can you share a bit more about the issues you are having? Would be happy to try to help resolve or open an issue if its a bug.
Keeping my fingers crossed it mades it!
That, and the plugin system.
Because it meant I could build on top of yarn a build/test system much like Bazel, Buck and Pants. But without the overhead of those tools.
Honestly, being able to build functionality into tooling like this is really awesome. Especially when it’s aware dependency graph.
I often have polyglot repos, with a heap of typescript, and some golang, and other stuff.
I spent a couple of weeks last year hacking away on a plugin, that can look at the whole dependency tree defined in yarn - and develop a build graph that can build everything in the required order, taking advantage of every cpu thread available. While keeping track of what’s previously been built.
From that, I extended the support to testing to do the same thing.
I wrapped it all up into a nice package and published it to:
Can be installed with this command
yarn plugin import https://yarn.build/latest
Then it’s just `yarn build` which runs `package.json#scripts.build`, and `yarn test` which runs `package.json#scripts.test`.—
Since then, there’s been plenty of development. I added a bundle command. You tell it which local package to bundle up, and it copies your repo to a temporary folder, removes everything that package doesn’t need (useful in a giant monorepo), leaves the other packages it depends on. Finally it adds a file `entrypoint.js` which sets up pnp for you, and re-exports the `main` file from your target package.
Then it zips it up for you ready for AWS Lambda (my use case), but also Docker and any other node runtime.
And recently I hacked another interesting plugin that yarn and pnp enabled. A really neat plugin that lets you write package.yaml instead of package.json.
If you replace package.json with package.yaml (or .yml), it will appear to yarn as a normal package.json. Everything works fine (with yarn, unsure about some node tooling), and you even get comments.
It’s a completely separate plugin (because it’s pretty out there), and it only has an effect if you don’t have a package.json in your package folder.
I’m using it on the golang packages in monorepo’s, because those developers are often a bit upset by seeing build tooling in a json file.
The package.yaml plugin can be installed with the following command:
yarn plugin import https://yarn.build/yaml
It’s still a bit experimental, but works pretty well.—
It’s all open source on GitHub, if you have any issues using it feel free to post a bug report.
10 is LTS
> This release marks the transition of Node.js 10.x into Long Term Support (LTS) with the codename 'Dubnium'. The 10.x release line now moves in to "Active LTS" and will remain so until April 2020. After that time it will move in to "Maintenance" until end of life in April 2021.
Node 10 is past EoL at this point. 12 and 14 are the current LTS releases: https://nodejs.org/en/about/releases/