Jo Liss
Jo Liss

Reputation: 32975

How to warn or error when using "npm install"

pnpm uses pnpm-lock.yaml as its lock file. I was hoping it might be able to write package-lock.json instead for interoperability with npm, but this doesn't seem to be possible.

Because of that, when collaborators accidentally run npm install instead of pnpm install, I'd like to print a warning or better yet, exit with an error, informing them to use pnpm instead. Is there a preferred way to do this?

Upvotes: 4

Views: 3476

Answers (1)

John
John

Reputation: 30195

This can be done with packages such as only-allow, only-allow-engines, or only-pnpm. These generally work either via a preinstall script or by (ab)using the "engines" property in package.json.

The node.js project is working on a better solution: corepack. Corepack will allow projects to specify their desired package manager via the "packageManager" property of package.json. However, as of 2022, corepack is still experimental and requires an explicit opt-in step (corepack enable). Unless you can rely on all collaborators having it enabled, it's not yet a viable solution.

Upvotes: 6

Related Questions