cornucopia icon indicating copy to clipboard operation
cornucopia copied to clipboard

Prevent mixing npm and pnpm in the project

Open codingmastergurkirat opened this issue 8 months ago • 1 comments

Problem

The project currently uses pnpm for dependency management, but it is still possible to run commands using npm.

Because of this, contributors may accidentally run:

npm install

instead of:

pnpm install

This can introduce conflicts in the repository.


Conflicts that can happen

When npm and pnpm are used side by side, several problems may occur:

  • Running npm install creates a package-lock.json file, while the project already uses pnpm-lock.yaml.
  • npm installs dependencies using a flat node_modules structure, while pnpm uses a stricter and different layout.
  • pnpm-specific configuration in package.json may be ignored when npm is used.
  • The dependency tree may become inconsistent between contributors' environments.
  • Builds or scripts may behave differently depending on which package manager was used.

These issues make debugging harder and reduce reproducibility for contributors and CI.


Proposed solution

To prevent these issues, the project could enforce pnpm usage by:

  1. Adding the following field to package.json:
"packageManager": "[email protected]"
  1. Optionally adding a preinstall check to prevent npm or yarn installs:
"preinstall": "npx only-allow pnpm"
  1. Updating documentation to consistently use:
pnpm install
pnpm run <script>

Question

If this sounds like a useful improvement, may I work on implementing this change?

This would be my first contribution to the project, and I would be happy to help improve the setup for contributors.

codingmastergurkirat avatar Mar 13 '26 21:03 codingmastergurkirat

@Gurkiratcodemaster I have assigned you. Thanks for reporting.

sydseter avatar Mar 19 '26 14:03 sydseter

Hi @sydseter, I see this issue was unassigned recently — I'd like to work on it if it's still open.

I reviewed the earlier closed PR (#2624) for context. The overall approach looks right:

  • Adding "packageManager": "pnpm@<version>" to package.json
  • Adding a preinstall script using only-allow pnpm to block npm/yarn installs
  • Updating documentation to consistently use pnpm commands

I noticed two small requested changes on that PR were never addressed before it was closed for inactivity — the .pre-commit-config.yaml version bump and a duplicate "Development server" headline in the README. I'll keep my PR scoped strictly to what's needed for this issue and avoid unrelated changes like that.

Happy to be assigned — thank you!

prajakta128 avatar Jul 28 '26 12:07 prajakta128

@prajakta128 Thank you for your time. I have assigned you.

sydseter avatar Jul 28 '26 12:07 sydseter