Isn't setting process.env in Electron app
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Electron main.js NODE_ENV is not available - Stack Overflow
So logically I want to do this via the process.env.NODE_ENV variable. This variable is set by Webpack in the webpack-config. The problem is...
Read more >Update json file with Environment Variable - Compiling ENV ...
In the Electron App that we develop at our company, ... First, create a config.json file that stores the list of env that...
Read more >Environment Variables - Electron
Environment Variables. Control application configuration and behavior without changing code. Certain Electron behaviors are controlled by environment variables ...
Read more >Hi, How to include the .env variable in Electron Builder
did you find any solution for setting variables and can change values after ... I use electron js for the first time ,...
Read more >ReferenceError: “process is not defined” - GIMTEC
In this case, process is not defined in the browser environment, hence the error. The solution is to remove the reference to process...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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: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
DefinePluginto specifyprocess.envoverwrote everything in node’s originalprocess.env(hence only seeingNODE_ENV). Closing as a configuration issue.