corepack
corepack copied to clipboard
Corepack enable does not symlink to npm.js
Is this an oversight or on purpose?
On purpose, see https://github.com/nodejs/corepack/tree/2470f58b74491a1301221df643c55be5adf1d349#corepack-enable--name
Ah ok. Still, adding it by default ensures that the correct npm version is used? Is that not desirable?
For the MVP we decided to leave it up to the npm project to decide whether they want Corepack to affect their binary by default or not. At the moment they didn't request it. If that's something you think would be a good idea, I think it'd be fair to raise the topic to them - I'm not aware of a public discussion yet 🤔
I'd even go so far as to expect that npm is actually calling corepack by default, since Node ships with both.
I opened https://github.com/npm/cli/issues/5109
If we allowing this, we can use it to use npm v6 for projects that don't want to upgrade lockfile to v2.
e.g.:
https://github.com/microsoft/TypeScript/blob/f8aa570b23bd094798a98cef307038b1da9101a7/package.json#L31
"packageManager": "[email protected]",
This does not work.
And NPM v7+ is annoying, it will upgrade and change the lockfile everytime but I cannot upgrade it. (See discussion in https://github.com/microsoft/TypeScript/issues/49726#issuecomment-1171463885)
@arcanis what would you consider as an official request from the npm team?
And for nodejs to ship with npm wrapped by corepack by default, what would need to happen?
@Jack-Works As the documentation mentions, you can explicitly enable it.
corepack enable npm
And for nodejs to ship with npm wrapped by corepack by default, what would need to happen?
- Someone opens a PR on nodejs/node changing the defaults.
- The PR gets approved and receives no objections (that's obviously the most tricky part).
- The PR lands, and the following release of Node.js ships with npm wrapped by Corepack by default.
As long as Corepack has not reached version 1.0.0, such initiative is very unlikely to succeed. If the initiative is not supported by the npm team, it's also unlikely to succeed.
I think because corepack is not symlinking to npm, when a project is configured to use another package manager, using npm does not throw error. That for me defeats the whole purpose of corepack...
"packageManager": "[email protected]"
- [x]
pnpm install->Usage Error: This project is configured to use yarn - [ ]
npm install-> works, would expect error
@Jack-Works As the documentation mentions, you can explicitly enable it.
corepack enable npm
This works for me.
> corepack prepare --all
Preparing [email protected]...
Preparing [email protected]...
Preparing [email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447...
> corepack enable
> npm -v
9.5.1
> corepack enable npm
> npm -v
9.6.5