hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
901 stars 57 forks source link

Can't get environment variables to replace #61

Open perenstrom opened 5 years ago

perenstrom commented 5 years ago

This is not an issue as much as a support question. But I couldn't find another forum.

My environment variables are not being replaced when running the following in my universal reactapp:

const envify = require('envify/custom');

// function declarations etc
  browserify()
    .transform(
      babelify.configure({
        ignore: [/(bower_components)|(node_modules)/]
      })
    )
    .transform(envify(process.env))
    .bundle()
    .on('error', handleError)
    .pipe(source('app.js'))
    .pipe(buffer())
    .pipe(gulpif(globalSettings.production, stripDebug()))
    .pipe(gulpif(globalSettings.production, uglify()))
    .pipe(gulp.dest(taskSettings.scripts.dest));

It works locally, but not in my staging environment where the server shows the correct stuff based on env, but is then being replaced by client hydration.

I've described my problem in more detail in this StackOverflow question: https://stackoverflow.com/questions/55594832/envify-not-replacing-my-environment-variables

Grateful for any help!

perenstrom commented 5 years ago

The devil is in the details. As I said in my question, the problem only occurred on my staging (and probably prod) server. So after a while I came across app.json, a Heroku settings file, partly responsible for sending setting which environment variables should be set.

So adding "FEATURE_EXAMPLE": { "required": false} in "env": {} in my app.json fixed the problem.

I'm still curious about why I still see the variable in my dist folder instead of it being replaced.