command not found with npm install –production by Josh Sherman

0
31

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:

Well of course husky is not installed, as it’s listed in devDependencies and we’re attempting to install the minimum amount of dependencies by way of the
--production (or --omit=dev) argument.

The issue is that regardless of which dependencies we’ve installed, the
prepare script in package.json is still attempting to run. With husky
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 DockerfileI ventured to solve this in the Dockerfile used to build the image. This approach, instead of munging with things in package.jsonmeans that any changes are isolated away from an engineer’s interaction with the code locally.

It seemed like the safer bet.

Since our 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 install:

npm set-script prepare ''

To put it all together inside of the Dockerfileit looked something like this:

RUN npm set-script prepare '' && npm install --production

With the prepare script set to an empty string, there’s no longer anything to error out and the npm install proceeds as expected!

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here