GulpUglifyError: unable to minify JavaScript
Closed this issue · 14 comments
Versions:
"gulp": "3.9.1",
"gulp-clean-css": "2.0.12",
"gulp-concat": "2.6.0",
"gulp-imagemin": "3.0.3",
"gulp-nodemon": "2.1.0",
"gulp-rename": "1.2.2",
"gulp-ruby-sass": "2.1.0",
"gulp-sourcemaps": "1.6.0",
"gulp-uglify": "2.0.0",
Code:
gulp.task('concat-prod', () => {
return gulp.src(jsFilesArray)
.pipe(concat('client.js'))
.pipe(gulp.dest('assets/build/'))
.pipe(uglify({mangle: false}))
.pipe(rename('client.min.js'))
.pipe(gulp.dest('assets/build/'));
});
Error:
internal/streams/legacy.js:59
throw er; // Unhandled stream error in pipe.
^
GulpUglifyError: unable to minify JavaScript
at createError (/home/user/user/client/node_modules/gulp-uglify/lib/create-error.js:6:14)
at wrapper (/home/user/user/client/node_modules/lodash/_createHybrid.js:87:15)
at trycatch (/home/user/user/client/node_modules/gulp-uglify/minifier.js:26:12)
at DestroyableTransform.minify [as _transform] (/home/user/user/client/node_modules/gulp-uglify/minifier.js:76:19)
at DestroyableTransform.Transform._read (/home/user/user/client/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:159:10)
at DestroyableTransform.Transform._write (/home/user/user/client/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:147:83)
at doWrite (/home/user/user/client/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:313:64)
at writeOrBuffer (/home/user/user/client/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:302:5)
at DestroyableTransform.Writable.write (/home/user/user/client/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:241:11)
at DestroyableTransform.ondata (internal/streams/legacy.js:16:26)
Why Use Pipeline? as linked from the README.
Hello,
This is a valid issue even with Pipeline enabled in v3.0.1 and should be reopened please.
const $ = require( 'gulp-load-plugins' )();
const DIST_CATALOG_DEV = 'dist/dev/proj_catalog/includes/assets'
const DIST_CATALOG_SRC = 'dist/plaintext/proj_catalog/includes/assets'
const DIST_CATALOG_PROD = 'dist/minified/proj_catalog/includes/assets'
GULP.task( 'javascript:catalog:extra', function() {
return PIPELINE(
GULP.src( ['src/assets/proj_catalog/javascript/**/*.js'] ),
// Concatenate streams into a single file
$.concat( 'catalog-extra.js' ),
$.cond( PRODUCTION, $.uglify( {preserveComments:"@license"} ) ),
$.cond( PRODUCTION, $.extname( '.min.js' ) ),
$.cond( PRODUCTION, GULP.dest( DIST_CATALOG_PROD + '/jscript' ) )
);
});
This is the error message even with Pipeline:
/user/Name/folder/my-project/node_modules/readable-stream/lib/internal/streams/pipeline.js:22
if (err) throw err;
^
GulpUglifyError: unable to minify JavaScript
at createError (/user/Name/folder/my-project/node_modules/gulp-uglify/lib/create-error.js:6:14)
at apply (/user/Name/folder/my-project/node_modules/lodash/_apply.js:16:25)
at wrapper (/user/Name/folder/my-project/node_modules/lodash/_createCurry.js:41:12)
at /user/Name/folder/my-project/node_modules/gulp-uglify/lib/minify.js:55:15
at DestroyableTransform._transform (/user/Name/folder/my-project/node_modules/gulp-uglify/composer.js:12:19)
at DestroyableTransform.Transform._read (/user/Name/folder/my-project/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
at DestroyableTransform.Transform._write (/user/Name/folder/my-project/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:83)
at doWrite (/user/Name/folder/my-project/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:428:64)
at writeOrBuffer (/user/Name/folder/my-project/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:417:5)
at DestroyableTransform.Writable.write (/user/Name/folder/my-project/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:334:11)
Not particularly enlightening and after hours of debugging, I found that what triggers the fail is passing options.
So, using $.uglify( {preserveComments:"@license"} )
or similar will fail and $.uglify()
will work.
Please look into this again.
Thanks
@dakanji What version of Gulp and Node.js are you running? Do you have a small code sample that results in that failure?
Hi,
$ node --version
v10.15.0$ npm --version
6.4.1$ npx --version
6.4.1$ gulp --version
[11:02:31] CLI version 2.0.1
[11:02:31] Local version 3.9.3
You will note I am on the unofficial Gulp v3.9.3 from https://github.com/electric-eloquence/gulp. However, I can confirm that the issue is the same on Gulp 3.9.1.
Please let me know what to add to the basic example in my first post.
Hi,
Is this reduced gulpfile not suitable?
const $ = require( 'gulp-load-plugins' )();
const DIST_CATALOG_DEV = 'dist/dev/proj_catalog/includes/assets'
const DIST_CATALOG_SRC = 'dist/plaintext/proj_catalog/includes/assets'
const DIST_CATALOG_PROD = 'dist/minified/proj_catalog/includes/assets'
GULP.task( 'javascript:catalog:extra', function() {
return PIPELINE(
GULP.src( ['src/assets/proj_catalog/javascript/**/*.js'] ),
// Concatenate streams into a single file
$.concat( 'catalog-extra.js' ),
$.cond( PRODUCTION, $.uglify( {preserveComments:"@license"} ) ),
$.cond( PRODUCTION, $.extname( '.min.js' ) ),
$.cond( PRODUCTION, GULP.dest( DIST_CATALOG_PROD + '/jscript' ) )
);
});
In any case, the issue is fairly simple to determine and can be summarised as:
Running gulp-uglify v3.0.1 and passing any option whatsoever causes it to fail. It works when no options are passed.
Pardon my lack of knowledge on this but can you be a bit more explicit about what you need?
Went back to gulp-uglify v2.1.2 which seems to work well.
I know but I can't get my head around getting the new version to work as I want.
I had ES6 code and that's why my gulpfile errored. I moved ES6 code to ES5 and now it work's like a charm! Thanks
Hi, I just land in this error:
GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected token: name (Adapter)
Uglify cannot parse ES6, it will throw you syntax errors. Either set TypeScript to target ES5, post-process your generated JS with babel, or use a different minifier.
Is an comment of 2016, is still valid?