Menu

1 / 2

Is this project npm, pnpm, Yarn 1 or Yarn 4? How to tell, and why Yarn is the tricky one

DEV Community: node·Alex·about 17 hours ago
#dfDlfOZ0
#devtonodejs#devto#dev#yarn#package
Reading 0:00
15s threshold

I maintain Slashi , a VS Code extension that, among other things, offers your project's commands in a popup: run a script, install dependencies, add a package. To do that it has to answer a question every editor plugin, CI script and onboarding doc eventually runs into: which package manager does this project use?

I assumed it was a lockfile check. It mostly is. The part that bit me came later, as a bug report: a Yarn 1 project where Slashi suggested yarn dlx , which doesn't exist in Yarn 1.

This post is the detection order I ended up with, the Yarn split that matters, and the cases it still gets wrong.

Step 1: trust packageManager first

If package.json has a packageManager field, it's the most explicit statement a project can make. Corepack reads it, and so should your tool.

{ "name" : "my-app" , "packageManager" : "[email protected]" }

Enter fullscreen mode

Exit fullscreen mode

Only the prefix before @ matters for picking the tool.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.