Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Heroku install devDependencies?

I would like to have Heroku build my app after I push it so that I don't have to push the build folder up every time I make a change. However Heroku only installs the dependencies from the package.json and grunt (my build tool) and all of its components are in devDependencies. I would like to keep them there where they belong. What's the workaround here?

like image 731
ionox0 Avatar asked Apr 09 '14 06:04

ionox0


People also ask

Does Heroku install devDependencies?

By default, Heroku will install all dependencies listed in package. json under dependencies and devDependencies . After running the installation and build steps Heroku will strip out the packages declared under devDependencies before deploying the application.

How do you install devDependencies?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.

Are Dev dependencies installed automatically?

The package is automatically listed in the package. json file, under the dependencies list (as of npm 5. previously, you had to manually specify --save ). When you add the -D flag, or --save-dev , you are installing it as a development dependency, which adds it to the devDependencies list.


2 Answers

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.

like image 151
Edo Avatar answered Oct 01 '22 08:10

Edo


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.

like image 35
PixnBits Avatar answered Oct 01 '22 10:10

PixnBits