I want to use the environment variable value set in the main process in the Lander process

For path reference between the development process and the deployment process, the path to my static resource was specified using environmental variables.

First, in electron/package.json

"main": "./src-gen/backend/electron-main-router.js"


// @ts-check
const path = require('path');
const { app } = require('electron');
const userHome = require('user-home');

let mainModulePath;

if (app.isPackaged) {
    mainModulePath = path.join(__dirname, '../../lib/backend/electron-main.js');

    process.env.RESOURCES_PATH = path.join(__dirname, '../../lib/resources')
} else {
    mainModulePath = path.join(__dirname, 'electron-main.js');

    process.env.RESOURCES_PATH = path.join(__dirname, '../../../myProject/src/resources')


I tried to use this in Lander’s process.


ReferenceError: process is not defined

How do you solve it?

I tried to use this in Lander’s process.

What is Lander?

ReferenceError: process is not defined

process should generally be defined as a global property in node.js. I’m not sure what’s wrong there. Can you provide a repo to reproduce the issue?

It’s a render process, not a Lander.

You are right. It should have been defined as a global attribute, but I didn’t think of it.

This problem has been resolved. Thank you.

Can I modify ‘src-gen/frontend/preload.js’?

I want to deliver environmental variables at the backend.

Can you tell me specifically how to set environmental variables as global attributes?

Generally, no file in src-gen should be modified - they are generated on each call of theia build.

You could set these environment variables in your own electronMain module contribution.