srod/node-minify

node-minify gets stuck or outputs "undefined" as content

hems opened this issue ยท 12 comments

hems commented

I'm running --compressor all on a large file, for example:
https://raw.githubusercontent.com/hems/efx-api-node/master/dist/efx-a3a245411be.js

but all i get on my console is a stuck screen:

image

node version: v9.1.1

and this is my package.json:

....
  "scripts": {
    "build": "npm run build:web:browserify; npm run build:web:minify; npm run build:web:hash",
    "build:web:browserify": "del ./dist/efx*.js; browserify ./src/efx.js --standalone EFX -o ./dist/efx.js",
    "build:web:minify": "node-minify --compressor all --input './dist/efx.js' --output './dist/efx.min.js'",
    "build:web:hash": "hash-filename ./dist/efx*.js;del ./dist/efx.js",
    "build:web:run": "browserify --debug ./src/efx.js --standalone EFX | browser-run --port 2222"
  },
  "dependencies": {
    "0x.js": "^0.38.4",
    "bluebird": "^3.5.1",
    "ethereumjs-util": "^5.2.0",
    "lodash": "^4.17.10",
    "request": "^2.87.0",
    "request-promise": "^4.2.2"
  },
  "devDependencies": {
    "browser-run": "^5.0.0",
    "browserify": "^16.2.2",
    "chai": "^4.1.2",
    "del-cli": "^1.1.0",
    "ganache-cli": "^6.1.4",
    "hash-filename": "^1.0.4",
    "mocha": "^5.1.1",
    "mochify": "^5.8.0",
    "nock": "^9.4.1",
    "node-minify": "^3.1.0",
    "standard": "^11.0.1",
    "web3": "^1.0.0-beta.34"
  }

Here is the repository with the code that is yielding that issue:
https://github.com/hems/efx-api-node

You should be able to reproduce the problem by:

git clone
cd efx-api-node
npm install
npm run build:web:browserify
npm run build:webminify
# by now you can go to ./dist and you will see the .min.js file content is "undefined"

I have tried running something like compressor --uglify but the best i can get is a file with "undefined" written inside.

What am i doing wrong?

having similar problem. Trying to execute uglifyjs but the params do not match with documentation of uglifyjs. Perhaps something needs updated in node-minify to catch up with new uglifyjs params. Also getting undefined whenever I try any advanced minify settings such as

'mangle':{ 'reserved':["jQuery","$","loc","data","app","workerMsg"], 'mangle-props':{ 'regex':"/^__/", 'reserved':["__super__"] } },

I ended up doing it like this after installing uglify-js for command line. Sorry, could not use node-minify

var cmd ="uglifyjs "+tmpfile+"_nc --warn --verbose --mangle reserved=['jQuery','$','loc','data','app','workerMsg'] --mangle-props regex=/^__/,reserved=[__super__] --comments --name-cache '/tmp/'+key+'-mangle.json' -o "+tmpfile; var child = exec(cmd, function (error, stdout, stderr) {

srod commented

I can see an error with uglifyjs :

{ SyntaxError: Unexpected token: keyword (const) at JS_Parse_Error.get (eval at <anonymous> (/Users/rodolphe/Downloads/efx-api-node/node_modules/uglify-js/tools/node.js:21:1), <anonymous>:73:23) at formatError (util.js:784:16) at formatValue (util.js:615:14) at inspect (util.js:328:10) at Object.formatWithOptions (util.js:182:12) at Console.(anonymous function) (console.js:193:15) at Console.warn (console.js:210:31) at /Users/rodolphe/Downloads/efx-api-node/node_modules/node-minify/bin/cli.js:46:11 at process._tickCallback (internal/process/next_tick.js:68:7) at Function.Module.runMain (internal/modules/cjs/loader.js:746:11) at startup (internal/bootstrap/node.js:240:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:564:3) message: 'Unexpected token: keyword (const)', filename: '0', line: 51934, col: 0, pos: 1939050 }

For the options, they are not implemented yet, I will do it.

Looks like uglify-js has an issue on minify js files written in es6 convention.

I resolved it by : require('uglify-js') -> require('uglify-es') on https://github.com/srod/node-minify/blob/develop/lib/compressors/uglifyjs.js#L13

srod commented

I've released 3.1.1 (https://github.com/srod/node-minify/releases/tag/3.1.1), can you try it for uglifyjs ?

srod commented

I've released 3.2.0, and added uglify-es.
I tested with efx-api-node, it's ok with it.

hems commented

@srod i just updated to 3.2.0, i'm running:

node-minify --compressor all --input './dist/efx.js' --output './dist/efx.min.js'

and i get

โœ– Error - file(s) not compressed with undefined (node:46174) UnhandledPromiseRejectionWarning: Error: Type "all" does not exist

srod commented

@hems are you installing node-minify using NPM ? not from GitHub ?

Could you try to delete your node_modules and npm install again ?

hems commented

@srod i installed from npm, v3.2.0 already deleted and installed node_modules again that's how i got to that error

hems commented

turns out ./dist/efx.js didn't exist when i ran the command and that was causing the problem.

it should actually have said the file didn't exist and not the compressor type!

anyway, i after i made sure the file works, i got the following error:

`
โœ” File(s) compressed successfully with babel-minify
โ ‹ Compressing file(s) with butternut...
<--- Last few GCs --->

[56725:0x103800000] 584054 ms: Mark-sweep 1263.0 (1491.5) -> 1262.9 (1492.0) MB, 4298.1 / 0.0 ms allocation failure GC in old space requested
[56725:0x103800000] 588302 ms: Mark-sweep 1262.9 (1492.0) -> 1262.9 (1449.0) MB, 4246.8 / 0.0 ms last resort GC in old space requested
[56725:0x103800000] 592277 ms: Mark-sweep 1262.9 (1449.0) -> 1262.9 (1443.0) MB, 3974.8 / 0.0 ms last resort GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x1fe5e6a55e9
1: split(this=0x1ff01602201 <Very long string[5907126]>)
2: guessIndent(aka guessIndent) [/Volumes/backpack/git/bfx/efx-api-node/node_modules/magic-string/dist/magic-string.cjs.js:197] [bytecode=0x1fec4bb14a1 offset=11](this=0x1fe2e9822d1 ,code=0x1ff01602201 <Very long string[5907126]>)
3: new MagicString$1 [/Volumes/backpack/git/bfx/efx-api-node/node_modules/magic-string/d...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
2: node::FatalTryCatch::~FatalTryCatch() [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
4: v8::internal::Factory::NewFixedArrayWithHoles(int, v8::internal::PretenureFlag) [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
5: v8::internal::Factory::NewJSArrayStorage(v8::internal::Handlev8::internal::JSArray, int, int, v8::internal::ArrayStorageAllocationMode) [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
6: v8::internal::Factory::NewJSArray(v8::internal::ElementsKind, int, int, v8::internal::ArrayStorageAllocationMode, v8::internal::PretenureFlag) [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
7: v8::internal::Runtime_StringSplit(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/h/.nvm/versions/node/v9.11.1/bin/node]
8: 0x3d3f57c842fd
9: 0x3d3f57cef40e
10: 0x3d3f57d3d196
11: 0x3d3f57d3d196
error Command failed with signal "SIGABRT".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
`

hems commented

to reproduce the error, please

git clone https://github.com/hems/efx-api-node
npm install
npm run web:build:browserify
npm run web:build:minify
srod commented

Yes, I saw this error too, this is why I'm removing the all type in the next release: #394
Please, stick with only one compressor, in your case, uglify-es is working fine.