Electron-packager: cannot find module


#1

I trying to package my app using electron-Packager and this command:

electron-packager . FooBar --platform=darwin --arch=x64 --version=0.36.9

(I’m using MacOsx) the app is created but when I run it I get a pop-up showing this:

Uncaught Exception:

Error: Cannot find module '/Users/myUser/myApp/FooBar-darwin-x64/FooBar.app/Contents/Resources/app/app:/host/menu.html'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Object.<anonymous> (/Users/myUser/myApp/FooBar-darwin-x64/FooBar.app/Contents/Resources/atom.asar/browser/lib/init.js:158:8)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Function.Module.runMain (module.js:457:10)
    at startup (node.js:151:18)
    at node.js:1007:3

in this folder : /Users/myUser/myApp/FooBar-darwin-x64/FooBar.app/Contents/Resources/app there is the entry pointing html file menu.html, but it seems electron cannot find it…

this is my app.js:

var app = require('app');  // Module to control application life.
var BrowserWindow = require('browser-window');  // Module to create native browser window.

var mainWindow = null;


// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {

  // Create the browser window.
  mainWindow = new BrowserWindow({width: 1024, height: 768});

  // and load the index.html of the app.
  mainWindow.loadUrl('file://' + __dirname + '/menu.html');

  mainWindow.openDevTools({detach: true});

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    mainWindow = null;
  });

});

Do you have any ideas on what could be the problem?

Thank you.


#2

Can you show the project tree? and i think mainWindow.on(‘closed’) is running too, try to take off from the running method


#3

Hi, thinks for your reply, this is the project tree:

so menu.html is in the root folder of my project.

Thank you.


#4

And this is the folder tree of the FooBar.app content:

sorry for two replies but I cannot upload more then one picture per reply.

I have also removed the “mainWindow.on(‘closed’,” part… But without luck… same error!


#5

Be careful not to include node_modules you don’t want into your final app. electron-packager, electron-prebuilt and .git will be ignored by default. You can use --ignore to ignore files and folders via a regular expression. For example, --ignore=node_modules/electron-packager or --ignore=“node_modules/(electron-packager|electron-prebuilt)”.

check https://github.com/electron-userland/electron-packager

I dont know if this can solve but I’m lookin for an answer, try to create a small project with one html file and see if you get the same error

these videos can help too https://www.youtube.com/watch?v=K-H2amwQ_pU&list=PL1QRvYV-LXn6ESBl7qm1teB1U1CK1B6gv


#6

Hi Venomlust, I fixed it there was a problem in my package.json file. But thanks for support, I didn’t know about the ignore option, Just stupid question, Is there a way to know which are the module used and which are not?

Thank you


#7

Hmm I not sure what do you mean with “know which are the module used and which are not” I think you can control with Grunt, Browserify, Bower? not sure but if you search on npm theres some packges for optimization or you can just do it by head.


#8

Thank you venomlust!


#9

I am having the same problem.What was the problem in package.json file ??