aljosa
November 26, 2019, 11:37am
1
I’m trying to modify package.json and delete package-lock.json.
This action is required to install and build project (git repo can’t be modified just to make it work w/ netlify).
You can add "preinstall": "node preinstall-script.js"
to package.json
.
luke
November 27, 2019, 7:00am
3
@aljosa , will the solution posted by @patarapolw work for you?
If not, or if there are other questions, please let us know.
aljosa
November 27, 2019, 11:36am
4
We moved away from Netlify and are now building everything w/ Github actions which includes deploying sites w/ zip file (using netlify api).
Haven’t tried the preinstall hook but I think it would work.
Thanks for suggestions.
Note to future people reading this conversation, preinstall
no longer runs before npm install as of npm v7
opened 03:30PM - 09 Feb 21 UTC
Release 7.x
Bug
Priority 1
<!--
Note: Please search to see if an issue already exists for your problem: ht… tps://github.com/npm/cli/issues
-->
### 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.
* I'm aware that a similar issue (#2253) was closed with an explanation of "works as intended". I'm requesting for this behavior of NPM v7 to please be reconsidered.
* This same issue appeared in npm@3 and was treated as a bug and fixed: https://github.com/npm/npm/issues/10379
* 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.
### Steps To Reproduce:
<!--
ex. steps to reproduce the behavior:
1. In this environment...
2. With this config...
3. Run '...'
4. See error...
-->
Clone [this minimal sample repo](https://github.com/t1m0thyj/npm7-preinstall-issue) 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 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.
### Environment:
<!--
ex.
- OS: Ubuntu 20.04
- Node: 13.14.0
- npm: 6.4.12
-->
- Ubuntu 18.04
- Node: 15.8.0
- npm: 7.5.3