Question

How to prevent npm install on App

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?


Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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:

package.json
  "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?