heroku-buildpack-nodejs icon indicating copy to clipboard operation
heroku-buildpack-nodejs copied to clipboard

No way to get production dependencies without NODE_ENV=production

Open holm opened this issue 7 years ago • 3 comments

In our staging environment we would like to use NODE_ENV=staging, but still only get production dependencies installed. That does not seem possible with the buildpack.

We use https://www.npmjs.com/package/config to manage configuration, which is based on NODE_ENV. This needs to be set correctly during install, as we use heroku-postbuild package script to compile bundles, and this depends on the configuration.

holm avatar Aug 17 '17 08:08 holm

Hi! If you set NPM_CONFIG_PRODUCTION=true you should still only install production dependencies, even with NODE_ENV=staging

heroku config:set NPM_CONFIG_PRODUCTION=true

jmorrell avatar Aug 17 '17 16:08 jmorrell

Yes but as I wrote in the description this changes the NODE_ENV, which has effects on the post build script, since the env will now always be production.

I find it a bit strange that the way to get not get dev dependencies is to overwrite the NODE_ENV, instead of just using the --production flag.

holm avatar Aug 17 '17 16:08 holm

My team has also been having this issue as we have a staging dyno that builds our slug before we promote that slug to production. And we didn't want the devDependencies to be included in the slug, so we set NPM_CONFIG_PRODUCTION. But because of this our staging dyno is now being run with NODE_ENV=production, which is causing problems for us.

For now we've had to use a separate environment variable APP_ENV which we've set NODE_ENV to right after booting up.

I've looked through this repo and couldn't immediately find where/how the npm install command is run, but would it be possible to have an env variable that either sets NPM_CONFIG_PRODUCTION only on the install command, or maybe some sort of configuration for the install command itself?

Khauri avatar Jun 11 '20 15:06 Khauri