You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ability to hook into NPM before dependencies are installed may not be best practice but is sometimes required. This is the primary reason why I use preinstall scripts.
If preinstall scripts run after dependencies are installed, they seem identical to postinstall scripts and there is no longer a reason for me to use them.
package1 - This package is designed to fail if installed standalone. It expects the file "temp.txt" to exist that has been generated by a parent package before install.
package2 - This package installs package1 as a dependency, and has a preinstall script that creates the file "temp.txt".
Run cd package2 && npm install.
With NPM v6, the install succeeds because the preinstall script creates "temp.txt" before package1 is installed.
With NPM v7, the install fails because the preinstall script creates "temp.txt" after package1 is installed.
Current Behavior:
In NPM v7 the preinstall script runs after dependencies are installed, which breaks backwards compatibility with NPM v6.
This may have been on purpose, but I do not see the behavior change listed under breaking changes.
https://blog.npmjs.org/post/626173315965468672/npm-v7-series-beta-release-and-semver-major
Expected Behavior:
The preinstall script should run before dependencies are installed.
Steps To Reproduce:
Clone this minimal sample repo which contains 2 packages:
package1- This package is designed to fail if installed standalone. It expects the file "temp.txt" to exist that has been generated by a parent package before install.package2- This package installspackage1as a dependency, and has a preinstall script that creates the file "temp.txt".Run
cd package2 && npm install.With NPM v6, the install succeeds because the preinstall script creates "temp.txt" before
package1is installed.With NPM v7, the install fails because the preinstall script creates "temp.txt" after
package1is installed.Environment: