Error after packaging the app


#1

My app has a tray icon and when you click on it, it launches a BrowserWindow where there is a react web app.

The issue:

After I’m packaging the app (tried Electron Packager & what the electron docs say) and running it, I’m getting an alert saying the following:

A JavaScript error occured in the browser process

Uncaught Exception:
TypeError: Error processing argument 0.
    at TypeError (native)
    at EventEmitter.<anonymous> (/Applications/Electron.app/Contents/Resources/app/main.js:15:13)
    at emitOne (events.js:82:20)
    at EventEmitter.emit (events.js:166:7)

So in my main.js file there is this line: appIcon = new Tray(iconPlain); which looks good compared to the docs. Also when I’m running the app using electron prebuild (electron .) everything works properly. Below you can find my main.js just in case I’m missing something.

var app = require('app');
var path = require('path');
var ipc = require('ipc');

require('crash-reporter').start();

var Menu = require('menu');
var Tray = require('tray');
var BrowserWindow = require('browser-window');

var iconPlain = path.join('./images/', 'github-tray-plain.png');
var iconGreen = path.join('./images/', 'github-tray-green.png');

app.on('ready', function(){
  appIcon = new Tray(iconPlain);
  initWindow();

  appIcon.on('clicked', function clicked (e, bounds) {
    if (appIcon.window && appIcon.window.isVisible()) {
      return hideWindow();
    } else {
      showWindow(bounds);
    }
  });

  function initWindow () {
    var defaults = {
      width: 400,
      height: 350,
      show: false,
      frame: false,
      resizable: false,
      'standard-window': false
    };

    appIcon.window = new BrowserWindow(defaults);
    appIcon.window.loadUrl('file://' + __dirname + '/index.html');
    appIcon.window.on('blur', hideWindow);
  }

  function showWindow (bounds) {
    var options = {
      x: bounds.x - 200 + (bounds.width / 2),
      y: bounds.y,
      index: path.join('./', 'index.html')
    };

    appIcon.window.setPosition(options.x, options.y);
    appIcon.window.show();
  }

  function hideWindow () {
    if (!appIcon.window) return;
    appIcon.window.hide();
  }

  ipc.on('reopen-window', function(event) {
    appIcon.window.show();
  });

  ipc.on('update-icon', function(event, arg) {
    var icon;
    if (arg == "IconGreen") {
      appIcon.setImage(iconGreen);
    } else {
      appIcon.setImage(iconPlain);
    }
  });

  app.dock.hide();
});

#2

Looks like you forgot to declare appIcon before assigning it new Tray(iconPlain);, though that should give a ReferenceError instead of a TypeError


#3

I added var appIcon = new...(how did I forget that?) but still getting the same error. It’s like it is complaining about new. Any ideas?


#4

The docs seem to only use absolute paths. Does it work if you path.resolve(path.join(...))?


#5

That’s interesting. Your idea was correct although it didn’t work (got a similar error). What worked is the following:

var iconPlain = path.join(__dirname, 'images', 'github-tray-plain.png');

Which make sense… Right?


#6

Glad to hear you solved it :smile: Makes sense if process.cwd() isn’t the same as the file you’re working in, yes.