ERROR: Invalid syntax. Default option is not allowed more than '2' time(s). Type "SETX /?" for usage

Viewed 771

I am using Windows 10. In CMD, I tried to execute the following command in my electron project:

setx GH_TOKEN "ghp_B3kYZy7OibM1Rka4Y3jLSiBUlvtSS717FhvE" npm run publish

And I got this error:

ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

The following code is the part of content of the Package.json file:

"scripts": {
    "publish": "electron-builder build -w -p onTagOrDraft"
  }

In the tutorial I am watching, this command is entered in the Mac operating system as follows, where it works properly: enter image description here

2 Answers

Use

setx GH_TOKEN "ghp_B3kYZy7OibM1Rka4Y3jLSiBUlvtSS717FhvE" && npm run publish

The && are necessary because there are two commands. Without the &&, the npm run publish will be passed as arguments to SETX

This error also occurs if the environment variable you're setting contains one or more spaces.

In this case, you may avoid the problem by enclosing the value in double quotes. Unlike SET, which would take the quotes to be part of the value, SETX excludes the quotes from your stored value.

The differences in space and quote handling by SET and SETX are shown in the examples below.

For SET with spaces, quotes are not needed (and if included, become part of the value):

Set a value                              View the value                              
-----------------------------            -----------------------------
C:\TEMP>set MYVAR=some value             C:\TEMP>set MY
                                         MYVAR=some value

C:\TEMP>set MYVAR="some value"           C:\TEMP>set MY
                                         MYVAR="some value"

For SETX with spaces, quotes are needed (and do not become part of the value):

Set a value                              View the value in a new window                      
-----------------------------            -----------------------------
C:\TEMP>SETX MYVAR some value
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

C:\TEMP>SETX MYVAR "some value"          C:\TEMP>set MY
SUCCESS: Specified value was saved.      MYVAR=some value
Related