UPDATE, Jan 09, 2012:
At first, I thought it was due to the single quotes within the template literal:
replyTo: `'MTN Support' <${functions.config().supportgmail.email}>`
But now, it's confirmed that even a normal template literal is not supported by grunt-contrib-uglify
:
throw new Error(`Unknown sender email address: ${mailOptions.from.address}.`);
Same Error:
Warning: Uglification failed.
Unexpected token: name «sender», expected: punc «,».
Line 90 in functions/app-functions.js,functions/index.js,functions/viewer-functions.js,functions/site-functions.js
Use --force to continue.
Note that even the uglify-js
alone could not parse this. I'm also aware of the harmony
or uglify-js-es6
version on GitHub, but as this is for production deployment purpose, I dare not use it because it has not been updated since 4 years ago.
So is it confirmed that grunt-contrib-uglify v5.0.0
is still not supporting ES6 Template Literals? Any other workarounds or alternative without changing the template literals to the traditional +
string concatenation? Thanks!
Original Question:
I have the following Gruntfile.js:
module.exports = function (grunt) {
grunt.initConfig({
// define source files and their destinations
uglify: {
files: {
src: 'functions/*.js', // source files mask
dest: '../project-staging/functions/' // destination folder
}
}
});
// load plugins
grunt.loadNpmTasks('grunt-contrib-uglify');
// register at least this one task
grunt.registerTask('default', ['uglify']);
};
When I run grunt
at the command line, I hit this error:
Warning: Uglification failed.
Unexpected token: string «MTN Support», expected: punc «,».
Line 44 in functions/app-functions.js,functions/index.js,functions/viewer-functions.js,functions/site-functions.js
Use --force to continue.
Aborted due to warnings.
Below is the code that causes the error:
var mailOptions = {
from: functions.config().supportgmail.email,
to: null,
cc: null,
bcc: null,
// This is the line that causes the error:
replyTo: `'MTN Support' <${functions.config().supportgmail.email}>`,
subject: null,
text: null,
html: null
};
I have no idea what the error means as I don't have any error running my code except when I try to uglify it with Grunt. I also heard that the latest version of grunt-contrib-uglify
already support ES6, so what else could it be? Below is the version of my Grunt and plugin, which I just installed today:
"devDependencies": {
"grunt": "^1.3.0",
"grunt-contrib-uglify": "^5.0.0"
}
Anyone knows what's wrong with my code? I don't think it make sense to change my code to the old way of string concatenation using the +
as the template string is everywhere in my entire project. Thanks in advance!
>> SyntaxError: "var-name" is redeclared
due to same variable declaration on different JS files. Same error reported here and GitHub. It's ok, I'll figure out something else, thanks. – Microprint