gulp-uglify
gulp-uglify copied to clipboard
nameCache option is causing trouble, error message is not helpful
Hello,
I am getting a very ambiguous error in my gulp task since I have added the nameCache
option to uglify
pipe 😕
Here is the complete error:
GulpUglifyError: unable to minify JavaScript
Caused by: TypeError: Cannot read property 'cname' of undefined
File: E:\Projects\<redacted>\background.js
It does give the line number and my background.js
script doesn't use any property called cname
, so I am not sure what is the issue. Here is my pipe:
.pipe(uglify({
mangle: {
toplevel: true
},
compress: {properties: false},
output: {quote_style: 3},
nameCache: {}
})).on('error', err => console.error(err.toString()))
It works perfectly without any warnings/errors if I remove nameCache: {}
Can anyone help me debug this? Thanks in advance! 😄
I've got a similar problem, where Uglify tries to read the unused property _walk
of null
... Though _walk
is defined nowhere in my code...
My task:
// Concat Plugins, Minify
gulp.task('concatenate_plugins', function () {
return gulp.src(['assets/js/plugins/**/*.js'])
.pipe(concat('plugins.js'))
.pipe(uglify({
compress: {
drop_console: true
}
}))
.on('error', function(err) {
console.error('Error in compress task', err.toString());
})
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(buildDir + '/assets'))
});
Output:
[] Using gulpfile C:\dev\<redacted>\gulpfile.js
[] Starting 'concatenate_plugins'...
Error in compress task GulpUglifyError: unable to minify JavaScript
Caused by: TypeError: Cannot read property '_walk' of null
File: C:\dev\<redacted>\assets\js\plugins.js
Process finished with exit code 0
The pipeline runs OK when not uglifying the code at all... Another task that runs uglify
in the same way, runs successfully...
EDIT: After some digging, and removing scripts one by one that were being concatenated, I found the culprit: Tether v1.4.5 broke minification. v1.4.4 did not have any issues... This seems to be related to this Tether-issue: https://github.com/HubSpot/tether/issues/291