Is it possible to pass ELECTRON_RUN_AS_NODE=true and ELECTRON_NO_ATTACH_CONSOLE=true without setting up Webpack? If so, can someone explain how? I've searched all day and tried a bunch of ideas I had, but no luck with any of them.
This isn't really a Forge-specific question.
What exactly are you trying to do?
I'm trying to set process.env.ELECTRON_RUN_AS_NODE and process.env.ELECTRON_NO_ATTACH_CONSOLE to true in my packaged application from electron-forge.
It's really clear how to do this with webpack, which is what I've used on all my previous Electron projects.
In webpack the relevant bit to do this would be:
new webpack.EnvironmentPlugin({
ELECTRON_NO_ATTACH_CONSOLE: true,
ELECTRON_RUN_AS_NODE: true,
}),
I'm wondering if it's possible to do it with electron-forge out of the box, without setting up an entire webpack config.
Are you trying to use those ELECTRON_* environment variables with the main process? With my understanding of ELECTRON_RUN_AS_NODE, it only makes sense to use that variable when you're forking a child electron process.
I don't necessarily know that I need ELECTRON_RUN_AS_NODE, as I'm troubleshooting, but I definitely need ELECTRON_NO_ATTACH_CONSOLE.
Basically, I've got an application using stdio that works on Mac, but not on Windows. I'm trying to troubleshoot it, but changing to more complex build system (webpack) to set the env variable introduces a lot of unknowns into the equation. Ideally I'm trying to set ELECTRON_NO_ATTACH_CONSOLE with just electron-forge so that I can troubleshoot this otherwise working setup.
Is there any way to do it without introducing webpack into the equation?
My only advice without actually testing it is to set process.env.ELECTRON_NO_ATTACH_CONSOLE before you require any modules in your main process.
Since this isn't Electron Forge specific, I'm closing this issue.
Unfortunately that doesn't work as intended. It would be great to be able to set just these couple of Electron specific environmental variables without needing to resort to Webpack.
You might want to try asking in the Electron Discourse forum.
Great suggestion. Thanks.
Setting ELECTRON_RUN_AS_NODE and ELECTRON_NO_ATTACH_CONSOLE in webpack will do absolutely nothing to Electron. Setting them in JS with process.env. ELECTRON_NO_ATTACH_CONSOLE = true in your main process will also do nothing.
Those two environment variables to be set before your app is launched in the initial environment. I.e. you need to set those variables either from your launcher script or your terminal before launching
@MarshallOfSound thank you so much. I searched for a looooong time and couldn't find a clear explanation which left my somewhat shooting in the dark.
It would be great to add that information in some form here: https://electronjs.org/docs/api/environment-variables
Most helpful comment
Setting
ELECTRON_RUN_AS_NODEandELECTRON_NO_ATTACH_CONSOLEin webpack will do absolutely nothing to Electron. Setting them in JS withprocess.env. ELECTRON_NO_ATTACH_CONSOLE = truein your main process will also do nothing.Those two environment variables to be set before your app is launched in the initial environment. I.e. you need to set those variables either from your launcher script or your terminal before launching