Npm preinstall not run when explicit Node version defined

The npm preinstall script is not run when a custom Node version is defined via the NODE_VERSION env variable or via the .nvmrc file (or at least with 16.14.0 LTS version).

Our use case is a private Github repository dependency (we followed the ​​Managing multiple environments docs) + a requirement to run another Node version than the default one. As a workaround we appended the .npmrc file directly to the repository root, but that breaks our local development.

Looks like it’s a NPM v7 bug/feature where preinstall is run after installing dependencies (but before a script with name install is run) - see [BUG] Preinstall script runs after installing dependencies · Issue #2660 · npm/cli · GitHub

So Cloudflare Pages is working as expected, but maybe a note in the documentation could be added that the preinstall workaround does not work with npm >= v7.

A nice feature for this would be to add a special env variable (e.g. NPMRC) that would populate the .npmrc file with the variable content or some other way to run a script before everything else.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.