navy1978
navy1978

Reputation: 1439

Electron-packager: cannot find module

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.

Upvotes: 30

Views: 61409

Answers (6)

Gerald Vidal
Gerald Vidal

Reputation: 65

What worked for me was whatever dependency you are trying to install, instead of having --save-dev just use --save

Upvotes: 2

Cedric Ipkiss
Cedric Ipkiss

Reputation: 6347

For me, I had to rebuild the electron app. Working with Ionic, first delete the /electron folder, then run:

npx cap add electron

Upvotes: 0

AhmedMaher
AhmedMaher

Reputation: 1771

what worked for me was modifying the reference to the main application file ie : main.js for newer electron versions or app.js for old versions of electron in package.json as follows :

"main": "app.js"

Upvotes: 1

Shan
Shan

Reputation: 619

So i had this same problem. Mine got solved when i cd in to my project folder and did

npm i -D electron@latest

Sometimes adding in package.json and npm install would not have installed it properly. Please lemme know if it worked for you.

Upvotes: 4

LachoTomov
LachoTomov

Reputation: 3708

For me the problem was that the module dependencies were listed in "devDependencies" in package.json

Moving them to "dependencies" and running npm install again solved the problem.

Upvotes: 5

phuongle
phuongle

Reputation: 1186

Two things you can try:

Upvotes: 27

Related Questions