Skip to content

docs(only-allow-pnpm): added option to enforce pnpm with package.json and .npmrc #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

karthikappiah
Copy link

@karthikappiah karthikappiah commented Jul 21, 2025

Hello team!

I propose a very non-invasive update to the documentation—a native solution to a bug that has spawned numerous issues on GitHub.

As described in this issue (and many more open and closed issues), the package only-allow cannot reliably prevent NPM commands from running (even as a preinstall script).

Therefore, I added an alternative—a native solution that simply specifies PNPM as packageManager in package.json and sets engine-strict as true in .npmrc. This prevents commands from anything other than what's specified as the package manager.

I also documented the option to install only-allow as a dev dependency for offline and CI/CD use cases.

Thank you,
Karthik Appiah

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

vercel bot commented Jul 21, 2025

@karthikappiah is attempting to deploy a commit to the pnpm Team on Vercel.

A member of the Team first needs to authorize it.

@karthikappiah
Copy link
Author

karthikappiah commented Jul 21, 2025

For easier reference, here is the alternative:

As per the NPM docs, to prevent the use of an unspecified package manager, you should:

  1. Create a file, if it doesn't already exist, named .npmrc at the root of your project.
  2. Toggle the following configuration variable in your .npmrc on:
engine-strict=true
  1. Specify the following fields in your package.json:
{
  "devEngines": {
    "runtime": {
      "name": "node",
      "onFail": "error"
    },
    "packageManager": {
      "name": "pnpm",
      "version": "10.13.1",
      "onFail": "error"
    }
  },
  "engines": {
    "node": ">=18.18.0",
    "pnpm": ">=10.0.0"
  },
}
  • Now, when you run npm i or npm i -D, these commands return this error (before the preinstall script can run):
username@hostname nodejs-project % npm i -D package
npm error code EBADDEVENGINES
npm error EBADDEVENGINES The developer of this package has specified the following through devEngines
npm error EBADDEVENGINES Invalid engine "packageManager"
npm error EBADDEVENGINES Invalid name "pnpm" does not match "npm" for "packageManager"
npm error EBADDEVENGINES {
npm error EBADDEVENGINES   current: { name: 'npm', version: '10.9.2' },
npm error EBADDEVENGINES   required: { name: 'pnpm', onFail: 'error' }
npm error EBADDEVENGINES }
npm error A complete log of this run can be found in: /Users/username/.npm/_logs/2021-08-21T00_00_00_000Z-debug-0.log

@karthikappiah
Copy link
Author

karthikappiah commented Jul 21, 2025

Sorry for the last-minute refinement, I'm done adding commits to this pull request.
My latest commit is 873885b, awaiting your review and approval!

@karthikappiah karthikappiah changed the title added alternative to only allow pnpm docs: added alternative to only allow pnpm Jul 21, 2025
@karthikappiah karthikappiah deleted the patch-4 branch July 21, 2025 20:45
@karthikappiah karthikappiah changed the title docs: added alternative to only allow pnpm docs: added another option to only allow pnpm Jul 21, 2025
@karthikappiah karthikappiah changed the title docs: added another option to only allow pnpm docs(only-allow-pnpm): added option to enforce pnpm with engine-strict=true Jul 21, 2025
@karthikappiah karthikappiah changed the title docs(only-allow-pnpm): added option to enforce pnpm with engine-strict=true docs(only-allow-pnpm): added option to enforce pnpm with package.json and .npmrc Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant