6

Topic : Heroku Problem : After installing my node js application in heroku, I made some changes in package.json. Now, when I am trying to push changes again, new dependencies are not getting installed. Heroku is picking the dependencies from cache.

How to disable cache in heroku ?

Anurag Singh Bisht
  • 2,683
  • 4
  • 20
  • 26
  • Have you tried creating a `npm-shrinkwrap.json`? If you installed new dependencies and [shrinkwrap](https://docs.npmjs.com/cli/shrinkwrap) your project then npm will install everything in the shrinkwrap using the exact versions – Andrew Lively Jul 12 '17 at 18:53
  • Hmm. I've never found heroku not update my package.jsom dependencies on a deploy. – Robert Moskal Jul 12 '17 at 19:32

2 Answers2

25

Thanks all for responding.

After much googling and spending time on my issue, I was able to solve my problem. I thought it would be better to post an answer if anyone faces the similar dilemma.

Below is the documentation, where I found my answer https://devcenter.heroku.com/articles/nodejs-support

  1. By default, in heroku production is set to true. That's why only dependencies get installed. ( & skips devDependencies )

    heroku config:set NPM_CONFIG_PRODUCTION=false
    

Set production to false, to force heroku to install all packages.

** Only do this if doing development.
  1. Heroku, by default, caches all the dependencies, so that the deployment is faster.

    heroku config:set NODE_MODULES_CACHE=false
    
    $ git commit -am 'disable node_modules cache' --allow-empty
    
    $ git push heroku master
    
    ** Preferable only if new dependencies are added in package.json
    
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Anurag Singh Bisht
  • 2,683
  • 4
  • 20
  • 26
3

I'm aware of answering this question now is too late but no wonder someone will need to solve this issue at anytime...

Anyways, you can clear the build cache of an app easily by installing heroku-builds plugin.

  1. Installation:

heroku plugins:install heroku-builds

  1. Usage:

heroku builds:cache:purge -a your-app-name

Note: The cache will be rebuilt on the next deployment. If you do not have any new code to deploy, you can push an empty commit.

$ git commit --allow-empty -m "Purge cache"

$ git push heroku master

Anis
  • 77
  • 2
  • 7