I am running an electron application with webpack and it seems to be pulling in the values from the .env file, but process.env isn't getting set.
I have placed the require('dotenv').config() at the entrance to the application where webpack starts building, which is my where all my vendor files live.
If I set a variable to the result of the require, it stores my variables, but when I go to use them only my Node_ENV variable is available.
.env
GAUTHID=secretID
vendor.js
module.exports = function() {
require('dotenv').config();
//lots of modules loaded in below
}
home.js
console.log(process.env)
logs => {NODE_ENV: 'Development'}
Wondering why it seems to access the values fine, but isn't saving them. I've tried different locations, using .load(), but all have no effect.
Can you provide a gist or similar example code to demonstrate how your project is laid out and the order of operations? As-is, I can't help 馃樋
I am also experiencing this problem.
@calebmer will you provide more details or example code to demonstrate the issue?
@maxbeatty The project was based off the electron react boilerplate (https://github.com/chentsulin/electron-react-boilerplate), angular has been swapped for react but that shouldn't make a difference. I'm requiring in dotenv in the vendor.js file.
I got dotenv working with that stack here. I'm very much so a webpack newbie. As I understand what was happening, their use of DefinePlugin to specify process.env overwrote everything in node's original process.env (hence only seeing NODE_ENV). Closing as a configuration issue.
@maxbeatty That works perfectly. Should have assumed it was a webpack issue. Thank you.
I guess the problem was not getting process.env in the Node side.
I'm also using electron-react-boilerplate and in webpack.config.main.prod.js, I added the following to inject the dotenv vars into webpack at build time:
import dotenv from 'dotenv';
/* webpack stuff */
new webpack.EnvironmentPlugin({
NODE_ENV: 'production',
...dotenv.config().parsed // <-- this line
}),
Most helpful comment
I'm also using
electron-react-boilerplateand inwebpack.config.main.prod.js, I added the following to inject the dotenv vars into webpack at build time: