Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables set on webpack.config.client.development.js are not respected. #19

Closed
JoseInTheArena opened this issue Feb 8, 2017 · 7 comments

Comments

@JoseInTheArena
Copy link

JoseInTheArena commented Feb 8, 2017

When I set an environment variable as in here: the values do not make it through. For example, if I add a new entry and then console.log it, I get undefined

@catamphetamine
Copy link
Owner

Provide an exact use case

@JoseInTheArena
Copy link
Author

JoseInTheArena commented Feb 8, 2017

I want to add a new env variable that has different values for production and development. I did so by adding it on the link I posted above and it's undefined. The env variable is for configuring an exception logging library.

@catamphetamine
Copy link
Owner

Post the exact code

@JoseInTheArena
Copy link
Author

On webpack.config.client.development.js I add SENTRY_DSN to process.env. Then I go to client/rendering-service/main.js and client/src/components/Menu.js and add console.log(process.env.SENTRY_DSN).

webpack.config.client.development.js

  // environment variables
  new webpack.DefinePlugin({
    process.env: {
      NODE_ENV: JSON.stringify('development'),
      BABEL_ENV: JSON.stringify('development/client'), 
      SENTRY_DSN: JSON.stringify('some value)
    },
    REDUX_DEVTOOLS : false  // enable/disable redux-devtools
  }),
);

client/rendering-service/main.js and client/src/components/Menu.js

console.log("SENTRY_DSN: ");
console.log(process.env.SENTRY_DSN);

Output on the terminal after running npm run dev

SENTRY_DSN: 
undefined

@catamphetamine
Copy link
Owner

Webpack variables aren't available in main.js

@JoseInTheArena
Copy link
Author

That's interesting. If I add the variable in webpack.config.js instead, it is available. I'll keep looking. Thanks for the help.

@catamphetamine
Copy link
Owner

No, it can not be available in main.js because it's unrelated to Webpack.
It is available only in Webpack-built code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants