corepack icon indicating copy to clipboard operation
corepack copied to clipboard

Corepack enable does not symlink to npm.js

Open wmertens opened this issue 3 years ago • 10 comments

Is this an oversight or on purpose?

wmertens avatar Jun 30 '22 13:06 wmertens

On purpose, see https://github.com/nodejs/corepack/tree/2470f58b74491a1301221df643c55be5adf1d349#corepack-enable--name

merceyz avatar Jun 30 '22 13:06 merceyz

Ah ok. Still, adding it by default ensures that the correct npm version is used? Is that not desirable?

wmertens avatar Jun 30 '22 13:06 wmertens

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 🤔

arcanis avatar Jun 30 '22 13:06 arcanis

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

wmertens avatar Jun 30 '22 13:06 wmertens

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)

Jack-Works avatar Jul 01 '22 02:07 Jack-Works

@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?

wmertens avatar Jul 01 '22 11:07 wmertens

@Jack-Works As the documentation mentions, you can explicitly enable it.

corepack enable npm

merceyz avatar Jul 01 '22 11:07 merceyz

And for nodejs to ship with npm wrapped by corepack by default, what would need to happen?

  1. Someone opens a PR on nodejs/node changing the defaults.
  2. The PR gets approved and receives no objections (that's obviously the most tricky part).
  3. 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.

aduh95 avatar Jul 04 '22 22:07 aduh95

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

ianldgs avatar Jul 11 '22 14:07 ianldgs

@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

Garfield550 avatar Apr 24 '23 07:04 Garfield550