Search code examples
javascriptnode.jsuglifyjs

Uglify JS API throws TypeError when executing example from github


I've installed uglify-js 2.2.2 and am attempting to use the API to minify some javascript from a node.js application, however I get a type error when trying to access the parser.

I am basing my attempts off of the github readme in the API section.

Here is my attempt / output from the node shell. Here I am not even trying to call the parse method, I'm just showing it is completely inaccessible.

$ node
> var jsp = require("uglify-js").parser;
  undefined
> jsp.parse
  TypeError: Cannot read property 'parse' of undefined
    at repl:1:5
    at REPLServer.self.eval (repl.js:111:21)
    at Interface.<anonymous> (repl.js:250:12)
    at Interface.EventEmitter.emit (events.js:88:17)
    at Interface._onLine (readline.js:183:10)
    at Interface._line (readline.js:501:8)
    at Interface._ttyWrite (readline.js:719:14)
    at ReadStream.<anonymous> (readline.js:105:12)
    at ReadStream.EventEmitter.emit (events.js:115:20)
    at emitKey (readline.js:1041:12)

Am I doing something wrong here or is there some sort of bug that I haven't found through google?


Solution

  • Turns out the "API" info from the github readme is out of date / incorrect.

    I dug this up, which appears to be correct. https://npmjs.org/package/uglify-js. Scroll down to the "API Reference" heading.