title: ElectronJS: Uncaught TypeError: Cannot read property "BrowserWindow" / "getCurrentWindow" of undefined
body: <p>First of all, I know that this is a question only a beginner would ask, but after going through more than 50 different solutions, uninstalling npm and installing yarn I have to ask this incredible dumb question.
  Why doesnt this work?
  I want to implement a simple titlebar using ElectronJS, the problem that I have is that the buttons (Close / Minimize / Maximize) do not work. The errors that I receive are the following:</p>
  <p>The minimize error: <code>titlebar.js:16 Uncaught TypeError: Cannot read property 'BrowserWindow' of undefined at HTMLButtonElement.maximizeApp (titlebar.js:16)</code></p>
  <p>The maximize error: <code>titlebar.js:16 Uncaught TypeError: Cannot read property 'BrowserWindow' of undefined at HTMLButtonElement.maximizeApp (titlebar.js:16)</code></p>
  <p>The quit error: <code>titlebar.js:21 Uncaught TypeError: Cannot read property 'getCurrentWindow' of undefined at HTMLButtonElement.quitApp (titlebar.js:21)</code></p>
  <p>The JavaScript file that I use to control this is called titlebar.js. This is it:</p>
  <pre><code>const remote_v = require(&quot;electron&quot;).remote;
  
  var minimize_v = document.getElementById(&quot;minimize&quot;);
  var maximize_v = document.getElementById(&quot;maximize&quot;);
  var quit_v = document.getElementById(&quot;quit&quot;);
  
  minimize_v.addEventListener(&quot;click&quot;,minimizeApp);
  maximize_v.addEventListener(&quot;click&quot;,maximizeApp);
  quit_v.addEventListener(&quot;click&quot;,quitApp);
  
  function minimizeApp(){
    remote_v.BrowserWindow.getFocusedWindow().minimize();
  }
  
  function maximizeApp(){
    remote_v.BrowserWindow.getFocusedWindow().maximize();
  }
  
  function quitApp(){
    remote_v.getCurrentWindow().close();
  }
  </code></pre>
  <p>Since many of the fixes for other problems like this is in the render process, this is the HTML File:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;head&gt;
          &lt;title&gt;Visionizer&lt;/title&gt;
  
          &lt;link rel=&quot;stylesheet&quot; href=&quot;css/editor.css&quot;&gt;
          &lt;link rel=&quot;stylesheet&quot; href=&quot;css/titlebar.css&quot; &gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class=&quot;container&quot;&gt;         
              &lt;div class=&quot;titlebar titlebarStyle&quot;&gt;  
                  &lt;div class=&quot;windowTitle&quot;&gt; Visionizer &lt;/div&gt;
                  &lt;div class=&quot;windowControls windowControlsStyle&quot;&gt;
                      &lt;button id=&quot;minimize&quot;&gt;-&lt;/button&gt;
                      &lt;button id=&quot;maximize&quot;&gt;[]&lt;/button&gt;
                      &lt;button id=&quot;quit&quot;&gt;x&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class=&quot;editorScreen&quot;&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;script src=&quot;js/titlebar.js&quot;&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>The weird thing about this is that, after much trying, I decided to copy the code from the tutorial from github, I thought that there may have been an error in my code that I was too dumb to see. It still didn't run. I uninstalled the package with <code>npm</code> and installed it with <code>yarn</code> using <code>yarn global add electron@latest</code> since some people suggested this.</p>
  <p>I do not know whether this is important at all, but I will also copy my code from the main.js-file below since I want to be sure that I included everything:</p>
  <pre><code>const { app, BrowserWindow } = require('electron')
  
  function createWindow () {
    const win = new BrowserWindow({
      width: 900,
      height: 800,
      minHeight: 650,
      minWidth: 600,
      frame: false,
      webPreferences: {
        nodeIntegration: true
      }
    })
  
    win.loadFile('editor.html')
    win.webContents.openDevTools()
  }
  
  app.whenReady().then(createWindow)
  
  app.on('window-all-closed', () =&gt; {
    if (process.platform !== 'darwin') {
      app.quit()
    }
  })
  
  app.on('activate', () =&gt; {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
  </code></pre>
  <p>And here is the package.json file:</p>
  <pre><code>{
    &quot;dependencies&quot;: {
      &quot;electron&quot;: &quot;^11.0.2&quot;
    },
    &quot;name&quot;: &quot;*******&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;**********&quot;,
    &quot;main&quot;: &quot;main.js&quot;,
    &quot;scripts&quot;: {
      &quot;start&quot;: &quot;electron .&quot;
    },  
    &quot;author&quot;: &quot;************&quot;,
    &quot;license&quot;: &quot;MIT&quot;
  }
  </code></pre>
  <p>Some questions on the internet were answered by saying that the project was started wrongly, I followed their advice, I start my projects using the <code>yarn start</code> command</p>
  <p>Thank you for reading through this.</p>