3

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?

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

you are a lifesaver. For posterity: var minifiedCode = require('uglify-js').minify('alert("foo");', {fromString: true});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.