-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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. |
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: |
As we're using yarn this is my Dockerfile hack to effectively disable just the prepare lifecycle script and not use the blanket --ignore-scripts argument, by using sed to delete the line.
|
I solved it by adding true, this way the process returns success even though husky doesn't exists "scripts": {
"prepare": "husky || true"
}
|
thought maybe someone need to see this. // .husky/install.mjs
// Skip Husky install in production and CI
if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
process.exit(0)
}
const husky = (await import('husky')).default
console.log(husky()) "prepare": "node .husky/install.mjs" source doc: https://typicode.github.io/husky/how-to.html#ci-server-and-docker this still gave me error though just to let you know
better to use this: #914 (comment) |
This wins the Internet for today! |
@lifeforced also works in windows? |
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: