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
husky install
fails when using --prod
#914
Comments
adding --ignore-scripts worked for me |
Thank you for the tips, maybe it could be added to the docs in case others face the same issue? |
Yes, good suggestion. PR welcome. |
I had a similar issue and the problem with using a blanket I don't know what the solution is, but it'll be difficult to consider |
I just hit this problem found this issue, and discovered that there is an official recommended approach, using the |
Most of the linked approaches wont help,
Additionally building docker images locally will not trigger I guess another hack that might work would be: # install all dependencies, get past prepare/postinstall
npm install --production=false
# remove all non-production dependencies
npm prune --production But that would be really wasteful and inefficient. |
For now i am using this solution |
"scripts": {
"prepare": "is-ci || husky install"
} works for me with one caveat: At least |
I have to disagree with you there.
I still value your suggestion thought. Maybe it will help someone else? |
I think this is related: #981. Core topic seems that the lifecycle hooks are sometimes triggering in circumstances where we don't want them to run (ci, installation as a dependency (production install)). I can see the appeal of having husky be agnostic to what enviroment it's being installed in, but the recommendations currently in the docs don't seem to cover all potential scenarios. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Valid issue IMO and the workarounds above are just workarounds. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I still consider this to be an issue. |
The way the package works after v4 is problematic as evident by this and other related issues reported in this repo. I wonder why author doesn't want to acknowledge that the new way of handling hooks is just too problematic (even if intentions were good) and probably should be reverted. |
I'm running into this out of the blue on I've deleted I've edited my deploy job to Big sad. |
I solved my occurance of this with @pinalbhatt 's suggestion of |
The "custom script" option listed in the husky docs worked best for me while deploying a small hobby project to Heroku, which is not supported by the
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
If `husky` is not present, `npm` fails to install `fetch-retry` as a dependency for `production` or `ci` environments. ``` npm ERR! code 127 npm ERR! git dep preparation failed npm ERR! command /home/ubuntu/.nvm/versions/node/v12.22.10/bin/node /home/ubuntu/.nvm/versions/node/v12.22.10/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/ubuntu/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit npm ERR! > fetch-retry@5.0.1 prepare npm ERR! > husky install npm ERR! npm WARN using --force Recommended protections disabled. npm ERR! sh: 1: husky: not found npm ERR! npm ERR! code 127 npm ERR! npm ERR! path /home/ubuntu/.npm/_cacache/tmp/git-clone-9f0cb372 npm ERR! npm ERR! command failed npm ERR! npm ERR! command sh -c husky install npm ERR! npm ERR! npm ERR! A complete log of this run can be found in: npm ERR! npm ERR! /home/ubuntu/.npm/_logs/2022-02-21T00_27_56_429Z-debug.log npm ERR! A complete log of this run can be found in: npm ERR! /home/ubuntu/.npm/_logs/2022-02-21T00_27_56_749Z-debug.log ``` They offer a few alternative to the "default install" here: https://typicode.github.io/husky/#/?id=disable-husky-in-cidockerprod. See also typicode/husky#914.
We're seeing this with Google App Engine (node flex environment), where it's Google doing the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
My 2 cents to this issue that make our CI pipelines fail too. Finally I think best options so far are:
I can't recommend the --ignore-scripts as it will avoid all other legitimate script to be run, it can't be a good solution. |
Just a nit pick, the npm command actually is |
I have solved the same problem by usage of an own tiny CLI: The only point - this module has to be then production dependency then . Meanwhile why I see is a good way
Alternative usage. If you wish not to have this module as a global dependency - you can also use npx:
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I still consider this to be an issue. |
I have tried alternative approaches instead of using
this will just show error when binary is not available. but using this script is a problem while also, while the most problematic place is CI invocation, the check should be really |
Updated version of the popular workaround for this given above from @pinalbhatt - since later npm versions give warnings that
( |
I wanted to say just use |
Yes - I like this the best as then I can document in that script why I have to do all these workarounds. With all other solutions they will just be undocumented workarounds buried in CI tools or package.json. |
There are a large variety of approaches, and not one is satisfying I personally prefer {
"prepare": "test -d node_modules/husky && husky install || echo \"husky is not installed\"",
} IMO, it's evidence that many projects are getting deployed with dev dependencies, which is sad to realize |
If you use command like
|
Best solution by far. Doesn't require extra packages, or modifying the run script. |
@malko Thanks for the tip, this actually did the job for me. 🙏 UPD: Had to adjust it a bit to make it also work in my local env: "prepare": "sh -c 'if [[ -x \"$(command -v husky)\" ]]; then husky install; fi'", |
My take: {
"prepare": "command -v husky &>/dev/null && husky install || true"
} Don't know how cross-env it is, but works just fine for me on linux. |
In version 8.x and above use --omit=dev flag to install only regular dependencies: |
I have a
package.json
similar to:Running
npm install --prod
(orNODE_ENV=production
) will only install production dependencies and thusnode_modules/.bin/husky
will not be present. In my case this happens when trying to build a docker container where I want to install only the production dependencies.What is the suggested way to handle this scenario?
With husky 4 it worked properly as
husky install
wasn't needed.The text was updated successfully, but these errors were encountered: