Isn't setting process.env in Electron app

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

32reactions
fccommented, Oct 1, 2018

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
    }),

6reactions
maxbeattycommented, May 31, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found