npmpnpm

trouble with npm preinstall script


I'm trying to make the jump to pnpm from npm. I found a helpful hint to keep from running "npm install" after I make the change as described here: https://pnpm.js.org/en/only-allow-pnpm

Unfortunately my preinstall lifecycle override doesn't get executed. Seems to simple enough but npm install still works when I run something like "npm install @types/jest"

package.json:

{
  "name": "react-sandbox",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "preinstall": "npx only-allow pnpm"
  }
}

npm version 6.14.2.

Any ideas?


Solution

  • Unfortunately, the preinstall script is executed only during argumentless installation. So when you run npm add @types/jest, that script will not be executed, thus npm won't be prevented from running.

    But it will fail when running npm install.

    As of now, there is no other way to prevent npm from execution.