0

I am attempting to make my first Electron app using Angular 18. I have followed a couple of tutorials closely, but I keep getting an error message when building the app. I created a basic service to handle the IPC functionality that lets the angular UI talk to the Electron functionality.

import { Injectable } from '@angular/core';
import {IpcRenderer} from 'electron';

@Injectable({
  providedIn: 'root'
})
export class IpcService {
  private ipc: IpcRenderer | undefined;
  constructor() {
    try {
      this.ipc = window.require('electron').ipcRenderer;
    } catch (e) {
      throw e;
    }
  }

  test(): void {
    this.ipc?.send("openModal")
  }
}

the line this.ipc = window.require('electron').ipcRenderer; seems to be causing this error on build: "An unhandled exception occurred: Cannot destructure property 'routes' of '(intermediate value)' as it is undefined."

When I remove that line, the app builds and loads normally, except of course the IPC won't work. I've can't seem to find anyone else having this issue so I feel like there's something obvious I'm missing. Thanks for the help!

1
  • You need to follow the examples on the IPC docs Commented Nov 7, 2024 at 19:18

1 Answer 1

-1

Have no idea why this is the case, but wrapping the window.require line in

if (typeof window !== 'undefined') {}

fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.