Skip to content

process.env is not preserved to the renderer process #5224

@gliheng

Description

@gliheng
  • Electron version: 37.6
  • Operating system: linux

I set some environment variable to process.env in the browser process, then start the renderer process, but I can not get the environment variable I have set on the renderer process.

I tested this on windows and mac, they worked!

Since my app rely on this environment passing to the renderer process, it would be great if the behaviors are the same across different platforms.

Activity

MarshallOfSound

MarshallOfSound commented on Apr 20, 2016

@MarshallOfSound
Member

Seems a bit strange to use environment variables for communication between processes 👍

But as a temporary workaround you might be able to use remote.getGlobal('process').env.

zcbenz

zcbenz commented on Apr 20, 2016

@zcbenz
Contributor

This is unfortunately an expected behavior and we are not able to fix it, you can find more about it in #3306.

myfrndjk

myfrndjk commented on Apr 9, 2017

@myfrndjk

Hi,

I am trying to use process.env.TZ = 'America/Managua'; in my app
if I give that in main process it is working fine, if I give that in render process no effect.
is there any way to achieve this.
I just need to change the time zone for every request.

dcsw

dcsw commented on Sep 27, 2017

@dcsw

In the rendering process, try using the following:

const electron = window.require('electron'); const remote = electron.remote; //... console.log(remote.process.env["TZ"]);

Change "TZ" to get other environment variable values.

myfrndjk

myfrndjk commented on Sep 28, 2017

@myfrndjk

@dcsw : Thanks for the update.
Already @MarshallOfSound has clarified this #9150

ryancwalsh

ryancwalsh commented on Dec 10, 2023

@ryancwalsh

Maybe this is outdated. I get Property 'remote' does not exist on type 'typeof CrossProcessExports'. ts(2339)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zcbenz@gliheng@ryancwalsh@dcsw@MarshallOfSound

        Issue actions

          process.env is not preserved to the renderer process · Issue #5224 · electron/electron