1

I'm trying to open a link from an electron app (using angular) on my default browser but I receive the following error:

Uncaught TypeError: fs.existsSync is not a function
    at Object.<anonymous> (vendor.bundle.js:160955)
    at Object../node_modules/electron/index.js (vendor.bundle.js:160961)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../src/app/components/issue/issue.component.ts (main.bundle.js:159)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../src/app/app.module.ts (main.bundle.js:75)
    at __webpack_require__ (inline.bundle.js:55)
    at Object../src/main.ts (main.bundle.js:644)
    at __webpack_require__ (inline.bundle.js:55)
    at Object.0 (main.bundle.js:662)

I've got a "(click)="onNavigate()"" on a button on my html component and this is the function:

import { shell } from 'electron';
...      
onNavigate() {
    shell.openExternal("http://www.google.com");
}
...

I have no idea what I am doing wrong and hope someone here can help me :)

C.OG
  • 6,236
  • 3
  • 20
  • 38
merstik
  • 101
  • 1
  • 11

1 Answers1

0

Using window.require instead of require is one way of avoiding the conflict between require since you're using webpack & it brings it's own require. Try:

const shell = window.require('electron');
...      
onNavigate() {
   shell.openExternal("http://www.google.com");
}
...
Neil P.
  • 1,026
  • 2
  • 15
  • 32
  • 1
    It kept opening the new window inside the scope of the app so I got over the problem using this way: mainWindow.webContents.on('new-window', (event, url) => { event.preventDefault(); electron.shell.openExternal(url); }) – merstik May 03 '18 at 12:28
  • That's actually what I'm doing in my App, handling it in the main process. I probably should've added it as an alternative on the answer. – Neil P. May 03 '18 at 21:51