maximegris / angular-electron

Ultra-fast bootstrapping with Angular and Electron :speedboat:
https://www.maximegris.fr/angular-electron/
MIT License
5.67k stars 1.37k forks source link

global is undefined in production environment with context isolation enabled #747

Closed thamizh-qwerty closed 1 year ago

thamizh-qwerty commented 1 year ago

Describe the bug I am using Angular and Electron with context isolation enabled in my application. In development mode, everything works fine, but in production mode, I am getting the global is undefined error. I have tried the following solutions without success:

To Reproduce

  1. Steps to reproduce the behavior:
  2. Enable context isolation in Electron.
  3. Build and run the application in production mode.
  4. Observe the global is undefined error.

Expected behavior The application should run without errors in production mode with context isolation enabled.

Screenshots 19 - Copy (2)

Additional context

Tried below solutions, none worked. Do you know the fix @maximegris ? https://github.com/webpack/webpack/issues/10035 https://stackoverflow.com/questions/65586906/react-and-electron-with-draft-js-global-is-not-defined/67336441#67336441 https://github.com/facebook/fbjs/issues/290 https://github.com/electron/forge/issues/1498 https://stackoverflow.com/questions/74718063/how-to-enable-context-isolation-in-electron-js-next-js-nextron

metalllus commented 1 year ago

@thamizh-qwerty just add (window as any).global = window; to your polyfills.ts

thamizh-qwerty commented 1 year ago

@thamizh-qwerty just add (window as any).global = window; to your polyfills.ts

Used the code in polyfills.ts, error still exists.

maximegris commented 1 year ago

@thamizh-qwerty I have no error when I do :

Changing contextIsolation breaks how electron is injected in the renderer global variable window so isElectron() function in electron.service.ts always return false in the default project template.

So context isolation may not be the issue here. Maybe the combinaison of other parameters you changed ? or a 3rd party library you are using on your project ? or the way you have exposed electron API from context bridge ?