Electron builder not copying my dist/node_modules directory in the right place

Viewed 751

I've got one node application which I'm already launching with Electron. Now, I want to package it with electron-builder, but I'm dealing with such an strange behaviour. Usually, when I build my application, a dist folder gets generated, containing all the transpiled javascript files and also the package.json. Then, I have to run npm i --production again there to set up my production dependencies. So what I want electron-builder to do is to copy exactly the dist directory as it is once everything is installed:

electron-builder build --linux AppImage

This is my package.json related config:

  "main": "dist/app.js",
  "build": {
    "appId": "my.app",
    "files": [
      "dist/**/*"
    ]
  },

I guess that with this configuration I'm telling it to copy the dist directory and its contents. The AppImage file gets built and if I unzip it, I can see a resources dir gets created inside, containing one app.asar file. If I extract the asar content, I can see node_modules gets placed at the same level than dist, and not inside of it!! So I have:

  AppImage
  -- resources
  ---- app.asar
  ------ node_modules
  ------ dist (everything except node_modules)

When I launch the application it obviously complains of not finding the node_modules. The docs say there's some default files pattern which can take precedence of what user has defined...

I also have tried:

"files": {
  "from": "dist",
  "to": "dist",
  "filter": ["**/*"]
}

And seems not being able to find the package.json file.

Somebody asked this similar question years ago, with no answer. Any help please?

1 Answers

Finally I found the way to do it, I had to tweak the configuration with a property that I found in the docs: includeSubNodeModules, which defaults to false and seems to include the node_modules subfolders in the output. Also I had to explicitly omit the root node_modules folder since I don't want it in the output.

  "build": {
    "appId": "myApplication",
    "files": [
      "dist/**/*",
      "!node_modules"
    ],
    "includeSubNodeModules": true
  },
Related