Electron-packager: How to set electron-packager start command?

Created on 28 Sep 2015  路  25Comments  路  Source: electron/electron-packager

This may be a dumb question, but I take the risk to ask it.
I have the following package.json :

{
    "name": "some-app",
    "description": "Some App",
    "version": "0.1.2",
    "main": "main.js",
    "scripts" : {
        "start": "electron ."
    },
    "repository": {
        "type": "git",
        "url": "https://github.com/FliiFe/App.git"
    },
    "dependencies": {
        "express": "",
        "electron": "",
        "portscanner": ""
    },
    "license": "Apache-2.0"
}

And it works with nmp start. Problem is : How to make it work with electron-packager ?

needs info question

Most helpful comment

If i don't get it wrong, i would suggest to do the following:

npm install electron-packager --save

Then define the package script:

"scripts" : {
  "start": "electron-packager . dist --platform=win32 --arch=x64 --version=0.33.3",
},

I would also suggest to have npm start (electron .) for dev and npm package(electron-packager . ...) to bundle the app.

All 25 comments

I'm not very well-versed in the npm ecosystem, but isn't npm start used for development? I suppose the question is, what do you expect the behavior to be?

Haha, you're right, but then how can I achieve that ? I want the app to start when I start the generated .exe file. Instead it starts the "default" electron app (with "drag you app here ..")

Just to be clear, you want npm start to generate the (presumably Windows) build for you, and then run that executable?

Nope. I have an app, that I currently run with electron . (which is stored in "start" command) . I want to pack everything. So what I want to achieve is that when the user clicks the generated app, it starts the app as expected. But it doesn't

OK, so you don't currently generate the app using electron-packager, and you wish to generate it?

I did generate it, but the resulting file was starting the default app (

Welcome to Electron

To run your app with Electron, execute the following command under your Console (or Terminal):

path_to_generated path-to-your-app
The path-to-your-app should be the path to your own Electron app, you can read the quick start guide in Electron's docs on how to write one.

Or you can just drag your app here to run it:

Could you please answer the questions in CONTRIBUTING.md?

_Which version of electron-packager are you using?_
I'm using 5.1.0
_What cli arguments are you passing?_
electron-packager SourceDir OutDir --platform=win32 --arch=x64 --version=0.33.3
_What platform are you running electron-packager on? What platform(s) are you building for?_
Running on Windows 10 x64 (in VirtualBox), building for the same.
_Is there a stack trace in the error message you're seeing?_
This is not an error.
_If possible, please provide instructions to reproduce your problem_
Simply make a new electron project, then use electron packager with above arguments.

Usually if you get the default "welcome to electron" app after packaging, it's because main isn't configured correctly in package.json to point to where your app's entry point is. I see you've configured main but are you sure it's pointing at the right module (and one that exists), and that your package.json is also making it into the packaged application?

What do you mean by "module" ? main points to the main js file to be executed

If i don't get it wrong, i would suggest to do the following:

npm install electron-packager --save

Then define the package script:

"scripts" : {
  "start": "electron-packager . dist --platform=win32 --arch=x64 --version=0.33.3",
},

I would also suggest to have npm start (electron .) for dev and npm package(electron-packager . ...) to bundle the app.

Okay, I got it to work. I just had to run it from _inside_ the directory with . as path. I think this can be considered as an issue...

If you think there's an issue here, could you please provide clear steps on how to reproduce the undesired behavior?

How to reproduce ?

  • Create an electron project, with package.js correctly made
  • Assuming project's directory is named proj, from the parent directory, run
electron-packager proj out --platform=win32 --arch=x64 --version=0.33.3

Expected behavior :

App generates in out/ directory. When launching out*.exe, it launches the app

Current behavior :

App generates in out/ directory. When launching out*.exe, it launches the _default electron app_

Update : This behavior was observed using Windows 10 x64 in a virtual machine. Didn't test on Linux yet

I've been experiencing the same issue as @FliiFe when using electron-packager on Yosemite. I have essentially the exact same error report as his previous comment.

Here's my command: ./node_modules/.bin/electron-packager ./dist MyApp --all --version=0.33.4 --asar --overwrite. I didn't install electron-packager globally.

The result of the command is a successful build, but when I try to open the MyApp.app, I get the "welcome to electron" message shown in previous comments. The MyApp.app/Contents/Resources/ directory shows both an app.asar and atom.asar file, so I assumed they were built correctly. If I change the of my command to . (the root directory of my git project), electron-packager runs and builds a working app, but the files weigh in at around 3-4 GB, depending on platform target.

When running the app with just electron (./node_modules/.bin/electron .), it works as expected (but not with ./node_modules/.bin/electron ./dist - The electron error states that the directory is not an electron app).

I haven't been able to address my issue yet, but I suspect that having my electron app in a ./dist directory with my main file running outside that directory is the source of the error.

Are there any recommendations for running an app from dist? I've currently got a simple Express app running in my package.json's main script (airbalancer.js), which is outside of the dist directory. Should I be putting that inside my dist and a package.json inside dist that reflects only the bare minimum needed for an electron app?

I can't seem to reproduce this on Linux. Here's what I did:

cd /tmp
git clone https://github.com/malept/gmusicprocurator-app.git app
cd app
npm install
make dist-linux-x64 # Only needed because of some pre-packaging steps
cd ..
app/node_modules/.bin/electron-packager app TestApp --platform=linux --arch=x64 --version=0.26.1 --out=/tmp/app-out --ignore=dist/
cd /tmp/app-out/TestApp-linux-x64
./TestApp

The app runs as expected.

I got this same issue on OS X 10.9 Mavericks. I don't even define a main entry point. For reference, try running electron-packager on the Menubar project. It doesn't work for me.

I get the default per this comment https://github.com/maxogden/electron-packager/issues/144#issuecomment-143804447. Not sure why it isn't just launching the app/menubar.

Please try the latest unreleased version (i.e., git master). electron-packager no longer copies the default app (per #206).

Please try the latest unreleased version (i.e., git master). electron-packager no longer copies the default app (per #206).

@malept: I got a similar problem. My app consists of a single window that's hidden by default. But when I package it and open the app, the default Electron app opens, as well as the hidden window of my app.

I tried updating to the newest electron packager version using NPM:

$ npm install -g https://github.com/electron-userland/electron-packager

And I package my app like this:

$ electron-packager . appname --platform=darwin --arch=x64 --version=0.36.11 --asar --overwrite

What else can I try? I should be using the newst electron-packager version and the default Electron app is still there.

So I found out what caused this in my app: I had some AppleScript code that gives focus to the last window when the app's window is hidden (to get OS X spotlight behaviour). So when the app is launched and I directly hide the main window, then it'll give focus to the last focused window, which apparently is the Electron default app. I fixed this by just checking the app name before giving focus.

But either way, I either didn't manage to really install the newest electron-packager, or the default app is still being copied.

This issue has kind of turned into a catch-all, so I'm going to close it.

IF YOU HAVE THIS PROBLEM

  • Read our docs on filing bugs and see if your specific problem already has another issue created for it (whether it's open or closed)
  • If you believe you have a _different_ set of problems, file a new issue and follow the directions in the GitHub issue template.

Hi everyone,
Is any way to protect ASAR file from unpackaging(generated by electron atom) so other can not able to modify my code.
If any one has any idea or other option to protect my code please suggest
Thanx in advance

@kumarom1203 this question is not relevant to this issue. I refer you to https://github.com/electron/asar/issues/46 instead, which is more relevant.

I know this is a closed ticket, but because this is where google sent me when trying to solve my problem, here's a potential solution:

On MacOS, if you have a dist/ folder, just copy your package.json into it. then everything should work smoothly

Was this page helpful?
0 / 5 - 0 ratings