Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dev dependencies needed for Heroku webpack build

Tags:

webpack

heroku

I was under the impression that I wouldn't need the devDependencies to be included when I deploy to Heroku a react based app, using Webpack. For example, here's my package.

  "scripts": {
    "test": "",
    "start": "./node_modules/.bin/babel-node server",
    "build": "rimraf dist && export NODE_ENV=production && webpack --config ./webpack.production.config.js --progress --profile --colors",
    "postinstall": "node deploy",
    "eslint": "eslint .",
    "jscs": "jscs ."
  },

and deploy.js:

  if (process.env.NODE_ENV === 'production') {
    var child_process = require('child_process');
    child_process.exec("webpack -p --config webpack.production.config.js", function (error, stdout, stderr) {
      console.log('stdout: ' + stdout);
      console.log('stderr: ' + stderr);
      if (error !== null) {
        console.log('exec error: ' + error);
      }
    });
  }

and the Procfile

web ./node_modules/.bin/babel-node server.js  

However, when I push to Heroku, I'm constantly getting a webpack command not recognized, so I included all of the devDependencies as normal dependencies to have it working. Am I missing something here?

like image 503
Detuned Avatar asked Jan 06 '23 18:01

Detuned


1 Answers

Heroku set NPM_CONFIG_PRODUCTION to true by default to install dependencies only. If you would like to install devDependencies, you can disable production mode:

$ heroku config:set NPM_CONFIG_PRODUCTION=false

However, since you usually don’t want all devDependencies in your production builds, it’s preferable to move only the dependencies you actually need for production builds into dependencies (bower, grunt, gulp, etc).

like image 93
charlesdg Avatar answered Jan 31 '23 00:01

charlesdg