Gatsby: Unknown argument: uglify

Created on 3 Apr 2018  Â·  29Comments  Â·  Source: gatsbyjs/gatsby

PR #4755 introduced a --no-uglify flag but it doesn't work for me when invoked from an npm script or via npx:

$ npx gatsby build --no-uglify
node_modules\gatsby\dist\bin\gatsby.js build

Options:
  -h, --help      Show help                                                       
  --verbose       Turn on verbose output                                          
  --no-color      Turn off the color in output                                    
  --prefix-paths  Build site with link paths prefixed (set prefix in your config).
  --no-uglify     Build site without uglifying JS bundles (for debugging).        
  -v, --version   Show version number                                             

Unknown argument: uglify

As a workaround, it is possible to do

$ npx gatsby build --noUglify

or

{
  "scripts": {
    "build": "gatsby build --noUglify"
  }
}

Note: I previously made it sound like the CLI parsing is incorrect but doing $ gatsby build --no-uglify (using global gatsby-cli) works correctly. Sorry!

question or discussion

Most helpful comment

Oh I just realized something – thanks, @pieh! An important detail in the OP, and also my miscommunication (sorry!) is that I'm actually running gatsby build from a package.json so Gatsby used is _local_. That probably makes a difference. These are exactly the things I can do, now:

$ npx gatsby --version
1.9.244

$ npx gatsby build --noUglify
# ... build output here ...
# it correctly builds which means that the `noUglify` parameter is understood

$ npx gatsby build --no-uglify
node_modules\gatsby\dist\bin\gatsby.js build

Options:
  -h, --help      Show help                                                                         [boolean]
  --verbose       Turn on verbose output                                           [boolean] [default: false]
  --no-color      Turn off the color in output                                     [boolean] [default: false]
  --prefix-paths  Build site with link paths prefixed (set prefix in your config). [boolean] [default: false]
  --no-uglify     Build site without uglifying JS bundles (for debugging).         [boolean] [default: false]
  -v, --version   Show version number                                                               [boolean]

Unknown argument: uglify

$ yarn run build
yarn run v1.5.1
$ gatsby build --no-uglify
node_modules\gatsby\dist\bin\gatsby.js build

Options:
  -h, --help      Show help                                                                         [boolean]
  --verbose       Turn on verbose output                                           [boolean] [default: false]
  --no-color      Turn off the color in output                                     [boolean] [default: false]
  --prefix-paths  Build site with link paths prefixed (set prefix in your config). [boolean] [default: false]
  --no-uglify     Build site without uglifying JS bundles (for debugging).         [boolean] [default: false]
  -v, --version   Show version number                                                               [boolean]

Unknown argument: uglify

Note how --noUglify works but --no-uglify doesn't so it's still likely a Gatsby issue, I would think.

All 29 comments

Hmmm I tested it locally without this problem. Wonder why I'm not seeing a problem.

I just reproduced on another PC (both are Windows machines if that matters). [email protected]

Hmmm well, I guess we should rename it then. camelCase on command line args offends some aesthetic sense of mine. How about instead we do --disable-uglify? You want to make a PR for this?

Weird this only shows up on windows.

/cc @tsriram

I think the way to handle this is to specify uglify parameter in yargs which will then parse --no-uglify as uglify: false. I'm not 100% sure though. Might try to do a PR but not sooner than this weekend I'm afraid.

Yeah, I think --disable-uglify is better and if at all someone wants to use yargs' boolean negation feature, they can use it like --no-disable-uglify. Guess we'll also need to change the --no-color command to --disable-color. I'll put up a quick PR in a while - @borekb hope you don't mind :smile:

Well, even if I change it to --disable-uglify, --no-disable-uglify doesn't seem to negate it :man_shrugging:
Anyway, disable sounds better to me than no

I actually think that --no- is sort of a standard convention, used by yarn, git, node and others. I'm not saying that it's possible to add --no- to any boolean flag so maybe this yargs feature should be disabled in Gatsby but --no-uglify feels better than --disable-uglify to me.

I disabled the boolean negation feature of yargs in https://github.com/gatsbyjs/gatsby/pull/3755 when I work on the no-color flag. It's strange that this problem happened.

What's weird also is it only seems to happen on windows — I can't reproduce the problem on my mac.

Same on linux. I can't reproduce it. The boolean negation is disabled in the package.json. It's possible to disable it at the creation of the parser. https://github.com/yargs/yargs-parser#configuration.
Maybe it will fix this problem.

Hmm why don't we tackle the actual problem then — @borekb could you file an issue with yargs to try to figure out why --no-uglify isn't working?

Agree that if it's indeed an upstream bug, it should be reported there. However, I'm not sure it is (feels quite weird that string parsing should be OS-dependent). I need to find some time to build a repro for the yargs issue, and generally to look more deeply into what's going on in Gatsby. So if you don't mind leaving this issue open for a little longer, I think I should be able to get to it in about a week or two.

@borekb could you try @cricrio's suggestion locally as well to see if it fixes the problem?

@KyleAMathews I'm stuck at step four (yarn test) of https://github.com/gatsbyjs/gatsby/blob/master/CONTRIBUTING.md#contributing-to-the-repo, a lot of tests are failing. Will try again later.

I cannot get the dev setup working on my Windows machine, are there any Gatsby devs on Windows who could advise? Or is there a better place (chat?) to ask?

But I can say that --no-color works for me while --no-uglify doesn't. Strange.

I tried this on windows and gatsby build --no-uglify works fine for me - this seems unrelated to this feature but probably something in your system but not sure what that could be

Not sure if this could be the problem but try these commands:

npm list gatsby-cli
npm list -g gatsby-cli

maybe one of these packages is not up to date

Oh I just realized something – thanks, @pieh! An important detail in the OP, and also my miscommunication (sorry!) is that I'm actually running gatsby build from a package.json so Gatsby used is _local_. That probably makes a difference. These are exactly the things I can do, now:

$ npx gatsby --version
1.9.244

$ npx gatsby build --noUglify
# ... build output here ...
# it correctly builds which means that the `noUglify` parameter is understood

$ npx gatsby build --no-uglify
node_modules\gatsby\dist\bin\gatsby.js build

Options:
  -h, --help      Show help                                                                         [boolean]
  --verbose       Turn on verbose output                                           [boolean] [default: false]
  --no-color      Turn off the color in output                                     [boolean] [default: false]
  --prefix-paths  Build site with link paths prefixed (set prefix in your config). [boolean] [default: false]
  --no-uglify     Build site without uglifying JS bundles (for debugging).         [boolean] [default: false]
  -v, --version   Show version number                                                               [boolean]

Unknown argument: uglify

$ yarn run build
yarn run v1.5.1
$ gatsby build --no-uglify
node_modules\gatsby\dist\bin\gatsby.js build

Options:
  -h, --help      Show help                                                                         [boolean]
  --verbose       Turn on verbose output                                           [boolean] [default: false]
  --no-color      Turn off the color in output                                     [boolean] [default: false]
  --prefix-paths  Build site with link paths prefixed (set prefix in your config). [boolean] [default: false]
  --no-uglify     Build site without uglifying JS bundles (for debugging).         [boolean] [default: false]
  -v, --version   Show version number                                                               [boolean]

Unknown argument: uglify

Note how --noUglify works but --no-uglify doesn't so it's still likely a Gatsby issue, I would think.

How do I tell in which version (and of which packages) shipped a particular PR? I'd like to check in which versions of gatsby (or gatsby-cli?) shipped https://github.com/gatsbyjs/gatsby/pull/4755.

(I've updated the OP to specifically mention the _local_ Gatsby dependency.)

@borekb you can check merge commit and see tags on github - it was added in [email protected] and [email protected]

Yeah, this looks like a yargs bug — could you file an issue upstream and try to get it fixed there?

@cricrio Does this look like a yargs but to you or a Gatsby misconfiguration?

A PR updating yargs by a couple of major versions was just merged. Maybe we can re-check this once a new version of gatsby-cli has been published.

I'm able to reproduce this on my mac if that helps:

$ yarn build
yarn run v1.6.0
$ gatsby build --no-uglify
gatsby build

Build a Gatsby project.

Options:
  --verbose       Turn on verbose output                                                        [boolean] [default: false]
  --no-color      Turn off the color in output                                                  [boolean] [default: false]
  --prefix-paths  Build site with link paths prefixed (set prefix in your config).              [boolean] [default: false]
  --no-uglify     Build site without uglifying JS bundles (for debugging).                      [boolean] [default: false]
  -h, --help      Show help                                                                                      [boolean]
  -v, --version   Show version number                                                                            [boolean]

Unknown argument: uglify

Does the same thing when run by NPM:

$ npm run build

> <project name>@0.1.0 build <project directory>
> gatsby build --no-uglify

gatsby build

Build a Gatsby project.

Options:
  --verbose       Turn on verbose output                                                        [boolean] [default: false]
  --no-color      Turn off the color in output                                                  [boolean] [default: false]
  --prefix-paths  Build site with link paths prefixed (set prefix in your config).              [boolean] [default: false]
  --no-uglify     Build site without uglifying JS bundles (for debugging).                      [boolean] [default: false]
  -h, --help      Show help                                                                                      [boolean]
  -v, --version   Show version number                                                                            [boolean]

Unknown argument: uglify
npm ERR! code ELIFECYCLE
npm ERR! errno 1

<...etc>

If there's any info I can give you guys about my setup I'm happy to.

While working on #7187, I ran into the same issue, yarn build --no-uglify, yarn build --no-color don't work for me. My setup:

 System:
    OS: macOS Sierra 10.12.6
    CPU: x64 Intel(R) Core(TM) i5-6360U CPU @ 2.00GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 8.9.4 - ~/.nvm/versions/node/v8.9.4/bin/node
    Yarn: 1.7.0 - ~/.yarn/bin/yarn
    npm: 6.3.0 - ~/.nvm/versions/node/v8.9.4/bin/npm
  Browsers:
    Chrome: 68.0.3440.106
    Firefox: 61.0.1
    Safari: 11.1.2
  npmPackages:
    gatsby: next => 2.0.0-beta.93 
    gatsby-image: next => 2.0.0-beta.7 
    gatsby-plugin-catch-links: next => 2.0.2-beta.7 
    gatsby-plugin-glamor: next => 2.0.0-beta.3 
    gatsby-plugin-sharp: next => 2.0.0-beta.7 
    gatsby-plugin-typography: ^1.7.18 => 1.7.19 
    gatsby-remark-autolink-headers: next => 2.0.0-beta.5 
    gatsby-remark-copy-linked-files: next => 2.0.0-beta.3 
    gatsby-remark-images: next => 2.0.1-beta.10 
    gatsby-remark-katex: next => 2.0.0-beta.3 
    gatsby-remark-prismjs: next => 3.0.0-beta.5 
    gatsby-remark-responsive-iframe: next => 2.0.0-beta.3 
    gatsby-remark-smartypants: next => 2.0.0-beta.3 
    gatsby-source-filesystem: next => 2.0.1-beta.10 
    gatsby-transformer-remark: next => 2.1.1-beta.6 
    gatsby-transformer-sharp: next => 2.1.1-beta.6 
    gatsby-transformer-yaml: next => 2.1.1-beta.3 

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ferMartz picture ferMartz  Â·  3Comments

signalwerk picture signalwerk  Â·  3Comments

rossPatton picture rossPatton  Â·  3Comments

dustinhorton picture dustinhorton  Â·  3Comments

kalinchernev picture kalinchernev  Â·  3Comments