Electron-builder: install-app-deps: Configuring yargs through package.json is deprecated

Created on 13 Mar 2019  Â·  13Comments  Â·  Source: electron-userland/electron-builder

  • Version: 20.39.0

  • Target: 4.0.8 on platform=win32 arch=x64

I have a few local native modules linked via file: in package.json.

> electron-builder install-app-deps

Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
  • electron-builder version=20.39.0
  • loaded configuration file=package.json ("build" field)
  • rebuilding native production dependencies platform=win32 arch=x64

What are the yargs errors about?

Most helpful comment

@ivancuric It's just weirdly documented.

As it says in the API docs:

image

Raw Options refer to the CLI options and there you'll find this:

image

So CLI equals API arguments, i.e. you'd have to pass the command line arguments into the package.jsons build-property and hope you place them at the right position in the tree.


Downside of this is obviously that you'd need several different scripts to pass data to the builder so that it does not always trigger a full chain-rebuild if you just want to drop a testing app into the release directory, so you'd have to do something like this to avoid this:

// Some script file, i.e. build.js
const builder = require('electron-builder')

// ... Some logic that builds up the build field, e.g.:
let options = {
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  }

builder.build(options).then((sth) => {
  // I have literally no idea what would be passed
  // during a successful call, maybe just dump it
  // to the console
  console.log(sth)
}).catch((e) => {
  // Some error handling
  console.error(e)
})

All 13 comments

I just discovered them myself. It appears that this pertains to the command line arguments. For instance, what I've been doing in my package.json for the last year was put these commands in the scripts section:

...
"scripts": {
        "postinstall": "electron-builder install-app-deps",
        "start": "electron .",
        "build:quick": "electron-builder --dir",
        "release:this": "electron-builder",
        "release:mac": "electron-builder --mac",
        "release:win": "electron-builder --win",
        "release:linux": "electron-builder --linux"
    },

And yargs is basically a JavaScript package that parses command line arguments.

So I'm pretty sure these warnings mean: "Please don't use --dir, --mac etc. anymore, but use the Javascript API directly!"

I.e.: Run electron-builder from within a node.js-script.

https://www.electron.build/api/electron-builder
I don't see any way to run it using the provided API.

@ivancuric It's just weirdly documented.

As it says in the API docs:

image

Raw Options refer to the CLI options and there you'll find this:

image

So CLI equals API arguments, i.e. you'd have to pass the command line arguments into the package.jsons build-property and hope you place them at the right position in the tree.


Downside of this is obviously that you'd need several different scripts to pass data to the builder so that it does not always trigger a full chain-rebuild if you just want to drop a testing app into the release directory, so you'd have to do something like this to avoid this:

// Some script file, i.e. build.js
const builder = require('electron-builder')

// ... Some logic that builds up the build field, e.g.:
let options = {
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  }

builder.build(options).then((sth) => {
  // I have literally no idea what would be passed
  // during a successful call, maybe just dump it
  // to the console
  console.log(sth)
}).catch((e) => {
  // Some error handling
  console.error(e)
})

Ah, thanks!

Thanks @nathanlesage

By the way on successful build it returns paths to all the packages built.

You're welcome! 🎉

And @mubaidr: classic.

Working build script:

const builder = require('electron-builder')
const Platform = builder.Platform

const config = {
  "win": {
    "target": [
      {
        target: ['nsis', 'zip', 'portable'],
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  }

builder
  .build({
    targets: Platform.WINDOWS.createTarget(),
    config,
  })
  .then(m => {
    console.log(m)
  })
  .catch(e => {
    console.error(e)
  })

This occurs for me even if I'm running electron-builder from the terminal, with and without options and even with things like --help and --version which are supposed to be run from the CLI.

configure "scripts": {
"postinstall": "electron-builder install-app-deps",
"start": "electron .",
"build:quick": "electron-builder --dir",
"release:this": "electron-builder",
"release:mac": "electron-builder --mac",
"release:win": "electron-builder --win",
"release:linux": "electron-builder --linux"
},
https://www.electron.build/api/electron-builder
Thanks!

image

Same problem here when I tried to run code containing in my package.json file from the CLI (Terminal) on MacOS Mojave (was working well 3 months ago before my yesterday Electron update).

  • Electron: 4.1.3
  • Electron-builder: 20.39.0

package.json

{
    "scripts": {
        "start": "electron .",
        "build": "electron-builder",
        "build-mac": "electron-builder --mac"
    },
    "build": {
        "appId": "com.myCompany.myApp",
        "productName": "myAppName",
        "copyright": "Copyright © 2019 myCompany",
        "mac":{
            "target":"mas",
            "type":"distribution",
            "provisioningProfile":"myApp.provisionprofile",
            "identity": "MyCompany (idNumber)",
        },
        "directories": {
            "output": "build"
        }
    }
}

When I try to run npm run build-mac it gives me this error message Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.

Thanks to @nathanlesage I finally found the solution. It wasn't really clear for me about where I should put the build.js file et how to execute it (I'm not a Node JS pro). If someone is in my case, here are more detailed steps:

  • Create a new JS file in the folder containing the package.json file.
  • You can give any name to this new JS file (eg: myCustomScript.js).
  • In this myCustomScript.js file you will use the electron-builder JS API to run your build instead of using the CLI command electron-builder --mac.
  • Put this script (from the electron-builder doc).
  • Change the targets property if needed and custom the config property.
  • In the config property you just have to copy paste the object contained in the "build" tree of your package.json. Then you can remove the "build" part from your package.json tree cause you don't need here anymore.
  • Finally, to call and execute your myCustomScript.js you can add a line in the scripts property of your package.json like this:
"scripts": {
    "myCustomScript": "node myCustomScript.js"
}
  • Then you can call it from the Terminal like this npm run myCustomScript

So now, my files looks like below and it works like a charm!

package.json (new)

{
    "scripts": {
        "start": "electron .",
        "build": "electron-builder",
        "myCustomScript": "node myCustomScript.js"
    }
}

myCustomScript.js

"use strict";

const builder = require("electron-builder");
const Platform = builder.Platform;

builder.build({
    targets: Platform.MAC.createTarget(),
    config: {

        "directories": {
            "output": "build"
        },
        "appId": "com.myCompany.myApp",
        "productName": "myAppName",
        "copyright": "Copyright © 2019 myCompany",

        "mac":{
            "target":"mas",
            "type":"distribution",
            "provisioningProfile":"myApp.provisionprofile",
            "identity": "MyCompany (idNumber)"
        }
    }
})
.then(() => {
    // handle result
    console.log('Build OK!');
})
.catch((error) => {
    // handle error
    console.log(error);
})

How about the --publish option? How should I apply this?

Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.

This warning is from yargs, not electron-builder, so it’s great to keep using the CLI.
I created a PR to fix this internal error: #3852

Was this page helpful?
0 / 5 - 0 ratings