Hlung
Hlung

Reputation: 14298

Skip "Installing dependencies with npm" step when pushing a Node.js app to Heroku

Running git push heroku master always triggers a step that prompts:

Installing dependencies with npm

This step loads and reinstalls all of the dependencies again even it already exists. This is very time consuming and I want to skip this step sometimes when I deploy that I know the dependencies are the same.

Is there any command or options that do this?

Upvotes: 6

Views: 3066

Answers (3)

Zen-Ventzi-Marinov
Zen-Ventzi-Marinov

Reputation: 4236

Simplest ways I've found are

heroku apps:rename newTemporaryName

then

heroku apps:rename originalName

or change the NODE_ENV and get it back to previous again.

heroku config:set NODE_ENV=dev

then

heroku config:set NODE_ENV=production

There are probably other, similar hacks but these should be sufficient.

Upvotes: 0

JBCP
JBCP

Reputation: 13485

Its been a long time since you asked this question, now the Heroku buildpack caches node_modules, so install times will be much faster.

If however you still want to block npm install, here is one solution.

As of when I write this, the default Heroku build pack does not allow skipping npm install entirely. You can see in the dependencies.sh file, this line will always run:

npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1

However, if you create a file called .npmrc in your project folder with the following contents:

dry-run

This will cause npm install to not modify your existing node_modules directory.

Note that this change will also apply to the npm prune command that Heroku runs, but WILL NOT apply to the npm rebuild command (which is probably fine).

Upvotes: 2

IvanM
IvanM

Reputation: 3053

try to remove

node_modules

for example from you .gitignore

Upvotes: 0

Related Questions