How to Use Corepack (Step-by-Step Guide)

Aug 12, 2025 · 2 min read · 236 Words · -Views -Comments · Programming
Node.js 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

While browsing the metamask-extension source code, I saw a field in package.json: “packageManager”: “yarn@4.9.1”, but when checking yarn on npm, the latest version is still 1.22.22. Strange, so how does the actual project install this v4 yarn? After careful investigation, I found that it uses corepack for package manager and version management.

Description

Corepack is an official Node.js project, not third-party. The current latest version is v0.34.0.

How to use corepack

corepack enable


# Use yarn, pnpm, npm etc. normally for package installation

yarn install
pnpm install
npm install

When executing these package commands, corepack will automatically switch to the specified version. If the package manager or that version of the package manager doesn’t exist, it will automatically install and switch to use it.

Is corepack built-in?

Starting from Node.js v16.9.0, Corepack is a built-in feature of Node.js

Is corepack enabled by default?

Actual testing shows that even Node.js v20 doesn’t have it enabled by default, you still need to manually corepack enable.

Final Thoughts

I personally think corepack does solve a pain point, because different versions of package managers have different behaviors when installing dependencies, often causing lock file changes, which is super annoying. This way everyone uses unified package managers and versions, so lock file changes become very stable. Of course, if you need to use package managers like yarn outside of projects, you still need to install them globally yourself.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover