modmoto
modmoto

Reputation: 3290

Modules not found in electron app after build on mac

I am on a small electron app right now that uses vue and typescript. When i run the app in dev mode, everything works fine, but when I build the app with electron builder some modules get lost somehow. In my case the modules adm-zip and sudo-prompt somehow vanish during the build. So when the app starts, i get an error on this lines const AdmZip = window.require('adm-zip'); I already tried to switch out the moduls with different ones, but that does not seem to matter. I guess it is a problem with webpack and typescript, but as I am not much of a webpack/electron guy, I surely miss something here. Other modules are working, like all the node stuff or the electron-store module that I am also using.

Is this a common problem and do i have to import the modules differently somehow? Import or the normal require do not work, I always have to do the window.require

This would be the repo: https://github.com/w3champions/w3champions-launcher on branch AddLauncherStuff

Upvotes: 2

Views: 1980

Answers (2)

modmoto
modmoto

Reputation: 3290

Ok, I finally found the problem: adm-zip has native dependencies and therefore you have to add it as a external dependency in the vue.config.js This should also work for other modules aswell, if they have depenant modules. I added the the following vue.config.js with adm-zip in the top folder of my project and now it gets baked into the built version. You do not have to add the vue.config.js to any build steps or anything, just adding it on the top of your project is good enough for webpack to pick it up.

module.exports = {
  pluginOptions: {
    electronBuilder: {
      externals: ['adm-zip']
    }
  }
}

Upvotes: 7

bhanuka.w
bhanuka.w

Reputation: 13

I executed "npm run build" with Admin privileges in Windows OS. Everything worked fine in my Windows.

I hope this article will help you.

https://www.christianengvall.se/electron-packager-tutorial/

Upvotes: 0

Related Questions