zsoltszabo / node-uglifier

Fully auto merging and obfuscating (uglify) a whole NodeJs project into one file with external files option. Thieves lose the module name and structure information, code runs faster. Makes deployement super easy! It can also separate a project's original files based on the dependency tree.
MIT License
179 stars 28 forks source link

throws requireStatements.each is not a function #20

Closed byteshiva closed 7 years ago

byteshiva commented 8 years ago

If I run thru the below code its throws error, since the return is a object not a function. Can you explain why its not working?

[root@appserver]# cat index.js 
#!/usr/bin/env node
require('log-timestamp');
require('./boot/AppS/index.js').start();

Error

        requireStatements.each(function(o, i) {
                          ^

TypeError: requireStatements.each is not a function
    at recursiveSourceGrabber (/root/server/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:153:27)
    at NodeUglifier.merge (/root/server/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:232:7)
    at Object.<anonymous> (/root/server/index.js:5:35)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)
byteshiva commented 8 years ago

related to : https://github.com/zsoltszabo/node-uglifier/issues/14

WindyPaper commented 8 years ago

I also have same problem.

byteshiva commented 8 years ago

I have a fix for it, convert all each to forEach, it would work. But now I'm another set of errors.

https://github.com/byteshiva/node-uglifier/commit/ede7a7572bc8895545866f7bd643d33241a68870

This is where I'm getting error.

new Function("MOZ_SourceMap", "exports", "DEBUG", FILES.map(function(file){
    return fs.readFileSync(file, "utf8");
}).join("\n\n"))(
    require("source-map"),
    UglifyJS,
    !!global.UGLIFY_DEBUG
);

Error:

undefined:1553
    throw new JS_Parse_Error(message, filename, line, col, pos);
    ^
Error
    at new JS_Parse_Error (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1545:18)
    at js_error (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1553:11)
    at croak (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2092:9)
    at eval (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2242:21)
    at eval (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2139:24)
    at if_ (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2415:44)
    at eval (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2238:24)
    at eval (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2139:24)
    at block_ (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2432:20)
    at eval (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:2193:29)
WindyPaper commented 8 years ago

I think maybe we use this library in a wrong way...

byteshiva commented 8 years ago

Probably maybe its because of dynamic requires.

Warning!:
unhandled require type in file: /var/www/boot.js the problematic statement: require("../serv/Q").createQ
(q) probably something fancy going on  the error: probably dynamic
Warning!:

Dynamic Require

Warning!:
unhandled require type in file: /var/www/boot.js the problematic statement: require(cnfg.app.main+"/db/DBMan")
.gInst() probably something fancy going on  the error: probably dynamic
Warning!:
eladnava commented 8 years ago

Happens to me as well, no dynamic requires in my project. Any ideas?

Ran it like this:

var NodeUglifier = require("node-uglifier");
var nodeUglifier = new NodeUglifier("server.js");
nodeUglifier.merge().uglify();

//exporting
nodeUglifier.exportToFile("ugly.js");
HefnySco commented 7 years ago

I also had the same error :( /home/srijan/uglify/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:151 requireStatements.each(function(o, i) { ^

TypeError: requireStatements.each is not a function at recursiveSourceGrabber (/home/srijan/uglify/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:151:27) at NodeUglifier.merge (/home/srijan/uglify/node_modules/node-uglifier/lib_compiled/NodeUglifier.js:230:7) at Object. (/home/srijan/uglify/uglifyjs.js:3:14) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7)

zsoltszabo commented 7 years ago

Hi the each ->forEach bug resolved.