Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue on update to 1.0.0 #27

Closed
CrackerakiUA opened this issue May 20, 2017 · 10 comments
Closed

Issue on update to 1.0.0 #27

CrackerakiUA opened this issue May 20, 2017 · 10 comments

Comments

@CrackerakiUA
Copy link

After update to 1.0.0 i get below error. I use your module inside mine.

Cannot read property 'replace' of undefined (line: undefined, col: undefined, pos: undefined
    at Transform.minify [as _transform] (\node_modules \gulp-minify\index.js:120:50)
    at Transform._read (\node_modules\gulp-minify\node _modules\readable-stream\lib\_stream_transform.js:184:10)
    at Transform._write (\node_modules\gulp-minify\nod e_modules\readable-stream\lib\_stream_transform.js:172:12)
    at doWrite (\node_modules\gulp-minify\node_modules \readable-stream\lib\_stream_writable.js:237:10)
    at writeOrBuffer (\node_modules\gulp-minify\node_m odules\readable-stream\lib\_stream_writable.js:227:5)
    at Transform.Writable.write (\node_modules\gulp-mi nify\node_modules\readable-stream\lib\_stream_writable.js:194:11)
    at DestroyableTransform.ondata (\node_modules\read able-stream\lib\_stream_readable.js:546:20)
    at emitOne (events.js:96:13)
    at DestroyableTransform.emit (events.js:188:7)
    at readableAddChunk (\node_modules\readable-stream \lib\_stream_readable.js:217:18)
    at DestroyableTransform.Readable.push (\node_modul es\readable-stream\lib\_stream_readable.js:176:10)
    at DestroyableTransform.Transform.push (\node_modu les\readable-stream\lib\_stream_transform.js:123:32)
    at DestroyableTransform.sourceMapWrite [as _transform] (C:\Users\crack\AppData\Roaming\npm\node_modul es\waw\node_modules\gulp-sourcemaps\src\write\index.js:61:10)
    at DestroyableTransform.Transform._read (\node_mod ules\readable-stream\lib\_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (\node_mo dules\readable-stream\lib\_stream_transform.js:147:83)
    at doWrite (\node_modules\readable-stream\lib\_str eam_writable.js:345:64)
    at writeOrBuffer (\node_modules\readable-stream\li b\_stream_writable.js:334:5)
    at DestroyableTransform.Writable.write (\node_modu les\readable-stream\lib\_stream_writable.js:271:11)
    at DestroyableTransform.ondata (\node_modules\read able-stream\lib\_stream_readable.js:546:20)
    at emitOne (events.js:96:13)
    at DestroyableTransform.emit (events.js:188:7)
    at readableAddChunk (\node_modules\readable-stream \lib\_stream_readable.js:217:18)
    at DestroyableTransform.Readable.push (\node_modul es\readable-stream\lib\_stream_readable.js:176:10)
    at DestroyableTransform.Transform.push (\node_modu les\readable-stream\lib\_stream_transform.js:123:32)
    at DestroyableTransform._transform (\node_modules\ gulp-ng-annotate\index.js:76:10)
    at DestroyableTransform.Transform._read (\node_mod ules\readable-stream\lib\_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (\node_mo dules\readable-stream\lib\_stream_transform.js:147:83)
    at doWrite (\node_modules\readable-stream\lib\_str eam_writable.js:345:64)
@simpleigh
Copy link

I'm seeing this issue as well, using version 1.0.0 on both Windows and Linux.

The call to uglify.minify() returns an error object, and things fall apart in the following line as code is undefined and so there's no replace() method:

mangled = uglify.minify(String(file.contents), uglifyOptions);
min_file.contents = new Buffer(mangled.code.replace(reSourceMapComment, ''));

(taken from https://github.com/hustxiaoc/gulp-minify/blob/1.0.0/index.js#L119-L120).

The error that is returned from uglify.minify() looks like this for me:

TypeError: Cannot read property 'transform' of null
    at eval (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4598:32)
    at Object.before (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7265:9)
    at AST_Node.eval [as transform] (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4451:35)
    at eval (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4482:31)
    at Object.before (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7265:9)
    at AST_Node.eval [as transform] (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4451:35)
    at eval (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4470:25)
    at doit (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:141:23)
    at MAP (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:167:52)
    at do_list (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4469:16)
    at eval (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4486:21)
    at Object.before (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7273:13)
    at AST_Node.eval [as transform] (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:4451:35)
    at Object.compress (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:7226:25)
    at Object.minify (eval at <anonymous> (\node_modules\uglify-es\tools\node.js:1:0), <anonymous>:12687:75)
    at eval (eval at <anonymous> (eval at <anonymous> (\node_modules\gulp\bin\gulp.js:3:1)), <anonymous>:1:18)

I'm using the following versions:

└─┬ gulp-minify@1.0.0
  └── uglify-es@3.0.15

@simpleigh
Copy link

This issue is related to #29 - the underlying error from uglify-es isn't handled correctly leading to the error accessing mangled.code.replace().

@simpleigh
Copy link

One more bit of context relating to the issue above - running uglifyjs from the command-line succeeds, suggesting that the error is related to the way it is invoked by gulp-minify rather than the uglify library itself.

@simpleigh
Copy link

I said:

One more bit of context relating to the issue above - running uglifyjs from the command-line succeeds, suggesting that the error is related to the way it is invoked by gulp-minify rather than the uglify library itself.

... but I'm afraid this is incorrect: I think the underlying error is in uglify-es. I've produced a reduced testcase as follows:

var uglify = require('uglify-es');

var mangled = uglify.minify(''
    + 'var a;'
    + '(function () { })(a = {});'
    + 'var a;'
);

console.log(mangled.error);

This still exhibits the error but does not have any dependencies on gulp-minify.

The above construct looks odd, but it comes about when using TypeScript namespaces across multiple separate files that are then concatenated together. I don't know if this is the cause of the issue @CrackerakiUA originally reported.

I guess there are a couple of potential improvements that might be helpful for this project:

  1. Fix the error handling (see error handling incorrect for uglify-es #29) so underlying library errors are exposed clearly.
  2. Allow the use of custom versions of uglify or uglify-es rather than requiring only the bundled version.

Running uglifyjs directly doesn't include the compress option by default, which is why this had succeeded on my original code. You'd hope I could therefore workaround the issue by passing compress: false as an option, but this then reveals issue #28...

@CrackerakiUA
Copy link
Author

CrackerakiUA commented Jun 6, 2017

I am not using TypeScript, but i guess it could be if one of the libs i am trying to minify use it. Also i agree very much with your second suggestion.

@simpleigh
Copy link

I think idea 2 above is going to become more important:

  1. Allow the use of custom versions of uglify or uglify-es rather than requiring only the bundled version.

From https://github.com/mishoo/UglifyJS2:

uglify-js only supports ECMAScript 5 (ES5).

From https://github.com/mishoo/UglifyJS2/tree/harmony:

uglify-es is an ECMAScript 2015 parser, minifier, compressor and beautifier toolkit

Updating to uglify-es will potentially break gulp-minify for anyone using earlier language versions.

@hustxiaoc
Copy link
Owner

Hi, sorry for the trouble. I've created a new tag es5 for ECMAScript 5, please install gulp-minify@es5 if you are using earlier language versions.

@simpleigh
Copy link

Cool - thanks very much. @CrackerakiUA does this fix your issue?

@CrackerakiUA
Copy link
Author

Yes

@yuduxyz
Copy link

yuduxyz commented Aug 29, 2018

I also encountered this issue, it came out to be the problem of mismatch of parentheses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants