user3056783
user3056783

Reputation: 2644

electron-builder fails building linux package on macos - Error: Unknown target: build

I'm using electron-builder to package my application. I have a dist/ folder where all resources are. main.js in root folder does not need any transpiling and includes main process code. This works well in development mode when launching using electron command.

I have electron-builder set up using package.json configuration:

  [...]
  "main": "./main.js",
  "build": {
    "appId": "com.electron.mycompany.myapp",
    "productName": "myapp",
    "linux": {
      "target": "deb"
    },
    "files": [
      "./dist",
      "./main.js"
    ]
  },
  [...]

I'm launching electron-builder like this: electron-builder -ml build. Macos build packages fine and I'm able to launch the application. However Linux build fails. I'm building Linux package on macos Catalina. It gives me error stack trace:

rebuilding native dependencies  [email protected] platform=linux arch=x64
  ⨯ Unknown target: build  stackTrace=
                             Error: Unknown target: build
                                 at createCommonTarget (/Users/username/Projects/myappnode_modules/app-builder-lib/src/targets/targetFactory.ts:90:11)
                                 at /Users/username/Projects/myapp/node_modules/app-builder-lib/src/linuxPackager.ts:65:18
                                 at mapper (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/targets/targetFactory.ts:57:16)
                                 at LinuxPackager.createTargets (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/linuxPackager.ts:63:7)
                                 at createTargets (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/targets/targetFactory.ts:64:12)
                                 at Packager.doBuild (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/packager.ts:442:28)
                                 at processTicksAndRejections (internal/process/task_queues.js:85:5)
                                 at executeFinally (/Users/username/Projects/myapp/node_modules/builder-util/src/promise.ts:12:14)
                                 at Packager._build (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/packager.ts:373:31)
                                 at Packager.build (/Users/username/Projects/myapp/node_modules/app-builder-lib/src/packager.ts:337:12)
                                 at executeFinally (/Users/username/Projects/myapp/node_modules/builder-util/src/promise.ts:12:14)
  • building embedded block map  file=dist/IJP Visualization Tool-1.0.0-alpha.1-mac.zip

I am not using any code signing (nor do I wish to). Is something misconfigured? It seems to be it but not sure what the problem is exactly.

Upvotes: 0

Views: 1727

Answers (1)

Alexander Leithner
Alexander Leithner

Reputation: 3442

As per the electron-builder CLI documentation, all platform switches accept a "target list", which in essence is what you configure in your package.json with your different platform entries (build.<platform>.target, e.g. build.linux.target).

However, by using these target lists, you can specify which targets you want to build and exclude all others. Since Linux' switch is the last in the switch list -ml, Electron Builder interprets this as though you want to pass it a target list. This does not apply to the macOS build step because then you would have to use -m <targets> -l <targets>, -ml <targets> apparently only applies to Linux.

Thus, by appending build to the command line, you tell Electron Builder to compile all configured targets for macOS but only build the Linux target called build. Since there is no such target, Electron Builder crashes. Removing build from your command will do the trick.

Upvotes: 1

Related Questions