Install devDependencies on Heroku Install devDependencies on Heroku heroku heroku

Install devDependencies on Heroku


UPDATE: as pointed out in the comments this is no more needed because since 2018 heroku changed its default behaviour and dev dependencies are automatically installed

ORIGINAL ANSWER

Heroku by default installs only the production dependencies, ignoring the development dependencies under devDependencies.

Setting the npm production variable to false do the trick:

heroku config:set NPM_CONFIG_PRODUCTION=false

More info are available at the Heroku Node.js Support page.


Keeping NPM_CONFIG_PRODUCTION true, I used Heroku's script hooks:

"scripts": {  ...  "heroku-prebuild": "export NPM_CONFIG_PRODUCTION=false; export NODE_ENV=; NPM_CONFIG_PRODUCTION=false NODE_ENV=development npm install --only=dev --dev",  "heroku-postbuild": "export NPM_CONFIG_PRODUCTION=true; export NODE_ENV=production;",   ...},

(Finally) worked for me.


scripts": {  ...  "heroku-prebuild": "npm install --only=dev"}

This was enough for me. Thanks to PixnBits for the hint about heroku-prebuild.Also - my problem was with babel. I ended up moving babel-preset-es2015 and other presets into dependencies otherwise babel complained about presets.

Update: 8/11/2017 I've been having trouble with this. It seems like things have changed (and npm is on 5.3 now). But what I see is that the heroku-prebuild script is getting run, and then the post-install script is getting run (but I was only trying to install -dev).

So what I have been doing that works is to just run:

heroku config:set NPM_CONFIG_PRODUCTION=false

And just leave it set that way. I'd love a better solution.