Recently, while attempting to build a Docker container, I ran into a bit of a
dilemma. Upon running
npm install --production I was greeted with this less
than ideal error message:
> @company/[email protected] prepare > husky install sh: husky: command not found
Well of course
husky isn’t installed, as it’s listed in
we’re attempting to install the minimum amount of dependencies by way of the
The issue is that regardless of which dependencies we’ve installed, the
prepare script in
package.json is still attempting to run. With
unavailable, we get an error.
After some research, this does appear to be a known issue with
husky that may
or may not be resolved at some point in the future.
As this is all happening inside of a
Dockerfile, I ventured to solve this in
Dockerfile used to build the image. This approach, instead of munging
with things in
package.json, means that any changes are isolated away from
an engineer’s interaction with the code locally.
It seemed like the safer bet.
package.json only has
husky install in the
prepare script, all
we needed to do was clear said script out in our
Dockerfile with the following
command and then proceed with our
npm set-script prepare ''
To put it all together inside of the
Dockerfile, it looked something like
RUN npm set-script prepare '' && npm install --production
prepare script set to an empty string, there’s no longer anything to
error out and the
npm install proceeds as expected!