2012-12-17 18 views
3

我已經安裝了uglify-js 2.2.2,並試圖使用API​​來從node.js應用程序中縮小一些javascript,但是在嘗試使用時出現類型錯誤訪問解析器。Uglify JS API在從github執行示例時拋出TypeError

我在API部分基於the github readme的嘗試。

這是我從節點shell的嘗試/輸出。在這裏,我甚至沒有試圖調用parse方法,我只是表明它完全無法訪問。

$ 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) 

我在這裏做錯了什麼,或者有沒有通過谷歌發現的某種錯誤?

回答

6

發現github自述文件中的「API」信息已過時/不正確。

我挖了一遍,看起來是正確的。 https://npmjs.org/package/uglify-js。向下滾動到「API參考」標題。

+1

你是一個救星。對於後人: 'var minifiedCode = require('uglify-js')。minify('alert(「foo」);',{fromString:true});'' – mikermcneil

相關問題