How to correctly build an electron nodejs program into an .exe?












1















I'm using Electron v2.0.8, Node v8.9.3, npm 6.4.1. I've created a simple "Hello world" program using html, css, js alongwith npm.



The program works really fine when I cd to the program directory and npm start. But when it is build(packaged) using, electron-packager <sourcedir> <appname> --platform="win32", the "sweetalert" is not showing its message, which did show when using npm start. But the buttons function as supposed. ("Clears the text field")



I suspect this has something to do with the file paths or something, but being new to this whole framework, I have no clue.



I don't know whether my whole "creating an .exe approach" is 100% correct or not. I've tried with electron-forge but it gave so many errors so I gave up on it and switched to electron-packager instead. None of the online helps work for me(I believe due to different versions) Someone please help.










share|improve this question























  • electron packager doesn't run your app, it packages it. npm start does run your app, showing for example sweetalert alerts

    – Luca Kiebel
    Aug 31 '18 at 17:39






  • 1





    @LucaKiebel I'm sorry if I have mistaken something. I get that npm start "runs" the app. But when I package the app using electron-packager, the .exe so created when run, does not show the sweetalert message which it is supposed to. But the sweetalert message is shown when run the program using npm start(without packaging). Could you please tell me what could be the reason for this?

    – stackUsr
    Aug 31 '18 at 17:50
















1















I'm using Electron v2.0.8, Node v8.9.3, npm 6.4.1. I've created a simple "Hello world" program using html, css, js alongwith npm.



The program works really fine when I cd to the program directory and npm start. But when it is build(packaged) using, electron-packager <sourcedir> <appname> --platform="win32", the "sweetalert" is not showing its message, which did show when using npm start. But the buttons function as supposed. ("Clears the text field")



I suspect this has something to do with the file paths or something, but being new to this whole framework, I have no clue.



I don't know whether my whole "creating an .exe approach" is 100% correct or not. I've tried with electron-forge but it gave so many errors so I gave up on it and switched to electron-packager instead. None of the online helps work for me(I believe due to different versions) Someone please help.










share|improve this question























  • electron packager doesn't run your app, it packages it. npm start does run your app, showing for example sweetalert alerts

    – Luca Kiebel
    Aug 31 '18 at 17:39






  • 1





    @LucaKiebel I'm sorry if I have mistaken something. I get that npm start "runs" the app. But when I package the app using electron-packager, the .exe so created when run, does not show the sweetalert message which it is supposed to. But the sweetalert message is shown when run the program using npm start(without packaging). Could you please tell me what could be the reason for this?

    – stackUsr
    Aug 31 '18 at 17:50














1












1








1


1






I'm using Electron v2.0.8, Node v8.9.3, npm 6.4.1. I've created a simple "Hello world" program using html, css, js alongwith npm.



The program works really fine when I cd to the program directory and npm start. But when it is build(packaged) using, electron-packager <sourcedir> <appname> --platform="win32", the "sweetalert" is not showing its message, which did show when using npm start. But the buttons function as supposed. ("Clears the text field")



I suspect this has something to do with the file paths or something, but being new to this whole framework, I have no clue.



I don't know whether my whole "creating an .exe approach" is 100% correct or not. I've tried with electron-forge but it gave so many errors so I gave up on it and switched to electron-packager instead. None of the online helps work for me(I believe due to different versions) Someone please help.










share|improve this question














I'm using Electron v2.0.8, Node v8.9.3, npm 6.4.1. I've created a simple "Hello world" program using html, css, js alongwith npm.



The program works really fine when I cd to the program directory and npm start. But when it is build(packaged) using, electron-packager <sourcedir> <appname> --platform="win32", the "sweetalert" is not showing its message, which did show when using npm start. But the buttons function as supposed. ("Clears the text field")



I suspect this has something to do with the file paths or something, but being new to this whole framework, I have no clue.



I don't know whether my whole "creating an .exe approach" is 100% correct or not. I've tried with electron-forge but it gave so many errors so I gave up on it and switched to electron-packager instead. None of the online helps work for me(I believe due to different versions) Someone please help.







node.js npm electron






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 31 '18 at 17:33









stackUsrstackUsr

517




517













  • electron packager doesn't run your app, it packages it. npm start does run your app, showing for example sweetalert alerts

    – Luca Kiebel
    Aug 31 '18 at 17:39






  • 1





    @LucaKiebel I'm sorry if I have mistaken something. I get that npm start "runs" the app. But when I package the app using electron-packager, the .exe so created when run, does not show the sweetalert message which it is supposed to. But the sweetalert message is shown when run the program using npm start(without packaging). Could you please tell me what could be the reason for this?

    – stackUsr
    Aug 31 '18 at 17:50



















  • electron packager doesn't run your app, it packages it. npm start does run your app, showing for example sweetalert alerts

    – Luca Kiebel
    Aug 31 '18 at 17:39






  • 1





    @LucaKiebel I'm sorry if I have mistaken something. I get that npm start "runs" the app. But when I package the app using electron-packager, the .exe so created when run, does not show the sweetalert message which it is supposed to. But the sweetalert message is shown when run the program using npm start(without packaging). Could you please tell me what could be the reason for this?

    – stackUsr
    Aug 31 '18 at 17:50

















electron packager doesn't run your app, it packages it. npm start does run your app, showing for example sweetalert alerts

– Luca Kiebel
Aug 31 '18 at 17:39





electron packager doesn't run your app, it packages it. npm start does run your app, showing for example sweetalert alerts

– Luca Kiebel
Aug 31 '18 at 17:39




1




1





@LucaKiebel I'm sorry if I have mistaken something. I get that npm start "runs" the app. But when I package the app using electron-packager, the .exe so created when run, does not show the sweetalert message which it is supposed to. But the sweetalert message is shown when run the program using npm start(without packaging). Could you please tell me what could be the reason for this?

– stackUsr
Aug 31 '18 at 17:50





@LucaKiebel I'm sorry if I have mistaken something. I get that npm start "runs" the app. But when I package the app using electron-packager, the .exe so created when run, does not show the sweetalert message which it is supposed to. But the sweetalert message is shown when run the program using npm start(without packaging). Could you please tell me what could be the reason for this?

– stackUsr
Aug 31 '18 at 17:50












2 Answers
2






active

oldest

votes


















4














For anyone else facing a similiar issue. Actually my program was built correctly and there was no error in the code.



What had happened was that the file paths were not correctly configured. When I manually copied the necessary files for the "sweetalert" to run, it showed up the message. Thus no errors specific to sweetalert.



I'll have to find a way to solve the 'path' issue anyways.



UPDATE:



Adding the code



"extraFiles": [
"folder_to_be_included_in_build"
],


into the package.json file now copies the needed folder during "building" the app. Now no need to copy the folder manually to the build.






share|improve this answer

































    2














    package.json etc...
    "repository": {
    "url": "https://github.com/your/repo.git",
    "type": "git"
    },
    "author": {
    "name": "Author name"
    },
    "main": "./afolder/main.js",
    "build": {
    "productName": "The product name",
    "compression": "maximum",
    "files": [
    "./afolder",
    "./node_modules",
    "./package.json"
    ],
    "appId": "any.id.app",
    "asar": true,
    "win": {
    "icon": "./your/icon/path/icon.ico",
    "target": "nsis"
    },
    "nsis": {
    "oneClick": false,
    "installerIcon": "./afolder/your/icon/path/icon.ico",
    "uninstallerIcon": "./afolder/your/icon/path/icon.ico",
    "perMachine": false,
    "deleteAppDataOnUninstall": true,
    "artifactName": "${productName} ${os} ${arch} v${version} setup.exe",
    "allowToChangeInstallationDirectory": true,
    "createDesktopShortcut": true,
    "createStartMenuShortcut": true,
    "shortcutName": "ShortcutName"
    },
    "asarUnpack": [
    //remove this comment ...
    //packages you want to include after install.
    //for e.g.
    "./node_modules/electron-window-state",
    "./node_modules/fs-extra",
    "./node_modules/7zip-bin"
    ],
    "npmRebuild": false,
    "nodeGypRebuild": false,
    "directories": {
    "output": "../installer/${productName} v${version} setup"
    }
    },
    "scripts": {
    "start": "electron .",
    "installer": "yarn build --x64"
    },
    package.json etc...



    1. You will need "npm install electron-builder yarn --save-dev"

    2. Amend your package.json file with the above content (change productName etc... to your custom needs)

    3. npm run installer

    4. you should see a folder called installer generated on the parent directory






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52120324%2fhow-to-correctly-build-an-electron-nodejs-program-into-an-exe%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4














      For anyone else facing a similiar issue. Actually my program was built correctly and there was no error in the code.



      What had happened was that the file paths were not correctly configured. When I manually copied the necessary files for the "sweetalert" to run, it showed up the message. Thus no errors specific to sweetalert.



      I'll have to find a way to solve the 'path' issue anyways.



      UPDATE:



      Adding the code



      "extraFiles": [
      "folder_to_be_included_in_build"
      ],


      into the package.json file now copies the needed folder during "building" the app. Now no need to copy the folder manually to the build.






      share|improve this answer






























        4














        For anyone else facing a similiar issue. Actually my program was built correctly and there was no error in the code.



        What had happened was that the file paths were not correctly configured. When I manually copied the necessary files for the "sweetalert" to run, it showed up the message. Thus no errors specific to sweetalert.



        I'll have to find a way to solve the 'path' issue anyways.



        UPDATE:



        Adding the code



        "extraFiles": [
        "folder_to_be_included_in_build"
        ],


        into the package.json file now copies the needed folder during "building" the app. Now no need to copy the folder manually to the build.






        share|improve this answer




























          4












          4








          4







          For anyone else facing a similiar issue. Actually my program was built correctly and there was no error in the code.



          What had happened was that the file paths were not correctly configured. When I manually copied the necessary files for the "sweetalert" to run, it showed up the message. Thus no errors specific to sweetalert.



          I'll have to find a way to solve the 'path' issue anyways.



          UPDATE:



          Adding the code



          "extraFiles": [
          "folder_to_be_included_in_build"
          ],


          into the package.json file now copies the needed folder during "building" the app. Now no need to copy the folder manually to the build.






          share|improve this answer















          For anyone else facing a similiar issue. Actually my program was built correctly and there was no error in the code.



          What had happened was that the file paths were not correctly configured. When I manually copied the necessary files for the "sweetalert" to run, it showed up the message. Thus no errors specific to sweetalert.



          I'll have to find a way to solve the 'path' issue anyways.



          UPDATE:



          Adding the code



          "extraFiles": [
          "folder_to_be_included_in_build"
          ],


          into the package.json file now copies the needed folder during "building" the app. Now no need to copy the folder manually to the build.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 1 '18 at 9:19

























          answered Aug 31 '18 at 20:49









          stackUsrstackUsr

          517




          517

























              2














              package.json etc...
              "repository": {
              "url": "https://github.com/your/repo.git",
              "type": "git"
              },
              "author": {
              "name": "Author name"
              },
              "main": "./afolder/main.js",
              "build": {
              "productName": "The product name",
              "compression": "maximum",
              "files": [
              "./afolder",
              "./node_modules",
              "./package.json"
              ],
              "appId": "any.id.app",
              "asar": true,
              "win": {
              "icon": "./your/icon/path/icon.ico",
              "target": "nsis"
              },
              "nsis": {
              "oneClick": false,
              "installerIcon": "./afolder/your/icon/path/icon.ico",
              "uninstallerIcon": "./afolder/your/icon/path/icon.ico",
              "perMachine": false,
              "deleteAppDataOnUninstall": true,
              "artifactName": "${productName} ${os} ${arch} v${version} setup.exe",
              "allowToChangeInstallationDirectory": true,
              "createDesktopShortcut": true,
              "createStartMenuShortcut": true,
              "shortcutName": "ShortcutName"
              },
              "asarUnpack": [
              //remove this comment ...
              //packages you want to include after install.
              //for e.g.
              "./node_modules/electron-window-state",
              "./node_modules/fs-extra",
              "./node_modules/7zip-bin"
              ],
              "npmRebuild": false,
              "nodeGypRebuild": false,
              "directories": {
              "output": "../installer/${productName} v${version} setup"
              }
              },
              "scripts": {
              "start": "electron .",
              "installer": "yarn build --x64"
              },
              package.json etc...



              1. You will need "npm install electron-builder yarn --save-dev"

              2. Amend your package.json file with the above content (change productName etc... to your custom needs)

              3. npm run installer

              4. you should see a folder called installer generated on the parent directory






              share|improve this answer






























                2














                package.json etc...
                "repository": {
                "url": "https://github.com/your/repo.git",
                "type": "git"
                },
                "author": {
                "name": "Author name"
                },
                "main": "./afolder/main.js",
                "build": {
                "productName": "The product name",
                "compression": "maximum",
                "files": [
                "./afolder",
                "./node_modules",
                "./package.json"
                ],
                "appId": "any.id.app",
                "asar": true,
                "win": {
                "icon": "./your/icon/path/icon.ico",
                "target": "nsis"
                },
                "nsis": {
                "oneClick": false,
                "installerIcon": "./afolder/your/icon/path/icon.ico",
                "uninstallerIcon": "./afolder/your/icon/path/icon.ico",
                "perMachine": false,
                "deleteAppDataOnUninstall": true,
                "artifactName": "${productName} ${os} ${arch} v${version} setup.exe",
                "allowToChangeInstallationDirectory": true,
                "createDesktopShortcut": true,
                "createStartMenuShortcut": true,
                "shortcutName": "ShortcutName"
                },
                "asarUnpack": [
                //remove this comment ...
                //packages you want to include after install.
                //for e.g.
                "./node_modules/electron-window-state",
                "./node_modules/fs-extra",
                "./node_modules/7zip-bin"
                ],
                "npmRebuild": false,
                "nodeGypRebuild": false,
                "directories": {
                "output": "../installer/${productName} v${version} setup"
                }
                },
                "scripts": {
                "start": "electron .",
                "installer": "yarn build --x64"
                },
                package.json etc...



                1. You will need "npm install electron-builder yarn --save-dev"

                2. Amend your package.json file with the above content (change productName etc... to your custom needs)

                3. npm run installer

                4. you should see a folder called installer generated on the parent directory






                share|improve this answer




























                  2












                  2








                  2







                  package.json etc...
                  "repository": {
                  "url": "https://github.com/your/repo.git",
                  "type": "git"
                  },
                  "author": {
                  "name": "Author name"
                  },
                  "main": "./afolder/main.js",
                  "build": {
                  "productName": "The product name",
                  "compression": "maximum",
                  "files": [
                  "./afolder",
                  "./node_modules",
                  "./package.json"
                  ],
                  "appId": "any.id.app",
                  "asar": true,
                  "win": {
                  "icon": "./your/icon/path/icon.ico",
                  "target": "nsis"
                  },
                  "nsis": {
                  "oneClick": false,
                  "installerIcon": "./afolder/your/icon/path/icon.ico",
                  "uninstallerIcon": "./afolder/your/icon/path/icon.ico",
                  "perMachine": false,
                  "deleteAppDataOnUninstall": true,
                  "artifactName": "${productName} ${os} ${arch} v${version} setup.exe",
                  "allowToChangeInstallationDirectory": true,
                  "createDesktopShortcut": true,
                  "createStartMenuShortcut": true,
                  "shortcutName": "ShortcutName"
                  },
                  "asarUnpack": [
                  //remove this comment ...
                  //packages you want to include after install.
                  //for e.g.
                  "./node_modules/electron-window-state",
                  "./node_modules/fs-extra",
                  "./node_modules/7zip-bin"
                  ],
                  "npmRebuild": false,
                  "nodeGypRebuild": false,
                  "directories": {
                  "output": "../installer/${productName} v${version} setup"
                  }
                  },
                  "scripts": {
                  "start": "electron .",
                  "installer": "yarn build --x64"
                  },
                  package.json etc...



                  1. You will need "npm install electron-builder yarn --save-dev"

                  2. Amend your package.json file with the above content (change productName etc... to your custom needs)

                  3. npm run installer

                  4. you should see a folder called installer generated on the parent directory






                  share|improve this answer















                  package.json etc...
                  "repository": {
                  "url": "https://github.com/your/repo.git",
                  "type": "git"
                  },
                  "author": {
                  "name": "Author name"
                  },
                  "main": "./afolder/main.js",
                  "build": {
                  "productName": "The product name",
                  "compression": "maximum",
                  "files": [
                  "./afolder",
                  "./node_modules",
                  "./package.json"
                  ],
                  "appId": "any.id.app",
                  "asar": true,
                  "win": {
                  "icon": "./your/icon/path/icon.ico",
                  "target": "nsis"
                  },
                  "nsis": {
                  "oneClick": false,
                  "installerIcon": "./afolder/your/icon/path/icon.ico",
                  "uninstallerIcon": "./afolder/your/icon/path/icon.ico",
                  "perMachine": false,
                  "deleteAppDataOnUninstall": true,
                  "artifactName": "${productName} ${os} ${arch} v${version} setup.exe",
                  "allowToChangeInstallationDirectory": true,
                  "createDesktopShortcut": true,
                  "createStartMenuShortcut": true,
                  "shortcutName": "ShortcutName"
                  },
                  "asarUnpack": [
                  //remove this comment ...
                  //packages you want to include after install.
                  //for e.g.
                  "./node_modules/electron-window-state",
                  "./node_modules/fs-extra",
                  "./node_modules/7zip-bin"
                  ],
                  "npmRebuild": false,
                  "nodeGypRebuild": false,
                  "directories": {
                  "output": "../installer/${productName} v${version} setup"
                  }
                  },
                  "scripts": {
                  "start": "electron .",
                  "installer": "yarn build --x64"
                  },
                  package.json etc...



                  1. You will need "npm install electron-builder yarn --save-dev"

                  2. Amend your package.json file with the above content (change productName etc... to your custom needs)

                  3. npm run installer

                  4. you should see a folder called installer generated on the parent directory







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 28 '18 at 19:31

























                  answered Sep 1 '18 at 17:49









                  Mic SelMic Sel

                  235313




                  235313






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52120324%2fhow-to-correctly-build-an-electron-nodejs-program-into-an-exe%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Create new schema in PostgreSQL using DBeaver

                      Deepest pit of an array with Javascript: test on Codility

                      Fotorealismo