By BrightP
It seems that the app platform always runs the npm install command when it’s building a component.
Since we compile our assets on our development platform the npm install command is unnecessary.
When the package.json file is removed it doesn’t run this command, but I want to keep this file in our repo.
Is there any reason this command is automatically executed. And is there any way to prevent this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
There isn’t a directly configurable option that stops npm install from running. The most flexible way to customize the build process is to use a Dockerfile which gives you complete control over the build process and the resulting container image.
For npm install specifically there is a workaround that you can use. If you do not need it at all, you can hijack the preinstall script to remove the file completely, like so:
"scripts": {
"preinstall": "[[ $STOP_NPM_INSTALL == 1 ]] && rm package.json || true"
},
If the STOP_NPM_INSTALL env var is set to 1, when npm install is run the package.json file will “self-destruct” stopping the install process without any errors. Otherwise the process continues as usual.
Deleting the whole file is a little crude but it works. You could expand it a bit to run an external script that more carefully only removes the dependencies field from the file if you wish.
I hope that helps! Out of curiosity, which programming language/build environment does your app use?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.