Issue with grunt-closure-tools: ERROR - There is a parse error due to using a reserved word as an

Currently, I am utilizing the "grunt-closure-tools" tool.

Initially, minifying a simple JS file was successful without any issues. However, encountering an exception arose when attempting to minify either the AngularJS or Bootstrap libraries:

Error: Command failed: build\lib\angular.js:9040 WARNING - Keywords and reserved words are not allowed as unquoted property names in older versions of JavaScript. If you are targeting newer versions of JavaScript, set the appropriate language_in option.

build\lib\angular.js:256: ERROR - Parse error. identifier is a reserved word */

build\lib\angular.js:258: ERROR - Parse error. identifier is a reserved word if (isNaN(msie)) {

...................

Here is a snippet from my Gruntfile.js:

module.exports = function(grunt) {

    grunt.initConfig({

        pkg : grunt.file.readJSON('package.json'),

        closureCompiler:  {
            options: {
                compilerFile: 'lib/google-closure-tools/compiler.jar'
            },
            minify: {
                files: [
                    {
                        expand: true,
                        src: ['build/**/*.js', '!build/**/*.min.js'],
                        ext: '.min.js'
                    }
                ]
            }
        }

    });

    grunt.loadNpmTasks('grunt-closure-tools');

    grunt.registerTask('closure', ['closureCompiler']);
};

Any assistance on this matter would be greatly appreciated.

Answer №1

To achieve minification, it is recommended to specify the language_in option as "ECMASCRIPT5".

Check out the Gruntfile.js configuration below:

module.exports = function(grunt) {

    grunt.initConfig({

        pkg : grunt.file.readJSON('package.json'),

        closureCompiler:  {
            options: {
                compilerFile: 'lib/google-closure-tools/compiler.jar',
                compilerOpts: {
                    language_in: "ECMASCRIPT5"
                }
            },
            minify: {
                files: [
                    {
                        expand: true,
                        src: ['build/**/*.js', '!build/**/*.min.js'],
                        ext: '.min.js'
                    }
                ]
            }
        }

    });

    grunt.loadNpmTasks('grunt-closure-tools');

    grunt.registerTask('closure', ['closureCompiler']);
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps can be taken to resolve the issue of "Access Denied: Invalid token, incorrect code"?

Assigned to me recently for a school project is a coding challenge that consists of various parts. The final task involves uploading to a private GitHub repository and submitting a completion request through a POST request under specific conditions. I hav ...

"Using Angular's NgFor directive to efficiently organize and collapse data within

I am currently working on displaying API data in a table using ngFor, and I am facing an issue with hiding/showing a specific row of details outside the ngFor loop. Since this line is not within the ngFor loop, I am unable to bind the data accordingly. Can ...

Would parallax stars be overwhelming for a webpage?

I'm a newcomer to the world of web development and I have an idea to make stars move across my website. However, I'm concerned about whether this might be too much for a simple website to handle. Is there a way to optimize the code? const canvas ...

EJS selectively displaying certain elements from an object

This particular issue has been baffling me. I have been passing an object into an ejs template and when I output that object, everything appears as expected: { _id: 5504a5e7ff67ac473dd7655c, code: 'GB', name: 'United Kingdom', slug: & ...

Explore a JSON structure and identify the parent key of a specific key:value pair

I may be new to coding, but I've hit a roadblock and can't seem to find the solution - despite numerous attempts on Google and StackOverflow. Behold, a JSON object: const json = { "catalog:aardvark": { "severity": "minor" }, ...

Capturing the Facebook Login Event to dynamically modify the content of the main webpage

My current project involves creating a Facebook-based login system using JavaScript. When a user clicks a button, I want one div to be replaced by another if the user is already logged in to Facebook. If they are not logged in, I prompt them to enter their ...

Enhance the numerical worth of the variable through the implementation of the function

I'm working on a JavaScript timer but I'm struggling with assigning the value of a parameter to a global variable. Currently, I can achieve this without using parameters, but I really want to streamline my code and reduce the number of lines. He ...

Error when using the array.filter() method with polygons

I am working with an array named coordinate that contains latitude and longitude values for a polygon. I am trying to find the maximum and minimum latitude/longitude stored in this array. My approach involves using the array.filter() method to filter the ...

What is the best way to add a "Save to Favorites" link within a modal window

I have integrated the NASA API to showcase images, where clicking on an image reveals a modal containing additional details. There is also a save to favorites functionality in the tutorial that allows users to save images and details to a local storage sec ...

Storing JavaScript functions in a MySQL database

Is there a way to save the output from a JavaScript function to MySQL? var macs = { getMacAddress : function() { document.macaddressapplet.setSep( "-" ); return (document.macaddressapplet.getMacAddress()); } } ...

I'm looking to integrate Jest in my React project with npm. How can I achieve

I've developed my application with create react app and npm. While reviewing the official documentation for jest at https://jestjs.io/docs/tutorial-react, I noticed that they only provide information on testing CRA apps using yarn. Does this suggest t ...

Tips for developing screen reader-friendly AJAX areas and managing updates to the DOM?

My interactive user process operates in the following manner: Users encounter a dropdown menu featuring a selection of cities. Upon picking a city, an AJAX request retrieves all buildings within that city and inserts them into a designated div (the AJAX ...

Using factories in controllers does not function properly in Angular 1.6

My head is spinning with this one. There are 3 files in play: app.js, app.services.provider.js, admin.js In app.js, I set up my module: (function() { angular.module('myApp', ['ngRoute']).config(function ($routeProvider) { ...

Submitting a POST request to paginate and sort the results

Currently, I have a system in place where a GET request is used to query the database and display the results. While this method works well, I am looking to transition it into a POST request. This would allow for a more flexible approach by handling JSON b ...

Eliminate parameter from URL

Here is the URL I am working with: http://my.site/?code=74e30ef2-109c-4b75-b8d6-89bdce1aa860 My goal is to redirect to this URL: http://my.site#/homepage To achieve this, I use the following code snippet: import { push } from 'react-router-redux& ...

Getting around CloudFlare's 100-second time-out restriction

Seeking a solution to AJAX-enable my reports and circumvent the 100-second time-out constraint enforced by CloudFlare for requests passing through its platform. For more information, visit Is it possible to increase CloudFlare time-out? The implementatio ...

What is the best way to halt Keyframe Animation once users have logged in?

To enhance user engagement, I incorporated keyframe animation into my login icon on the website. The main objective is to capture the attention of visitors who are not registered users. However, once a user logs in, I intend for the keyframe animation to c ...

In Vue3, have you ever wondered why the $emit function seems to work fine before a promise fetch,

https://i.sstatic.net/yJmDY.jpg I have encountered an issue while attempting to pass the result of a promise fetch from a child component to a parent component using emit. Strangely, the emit function was working perfectly fine before the $fetch operation, ...

Designing a sequential bar graph to visualize intricate data using AmCharts

I received the following response from the server in JSON format: [{ "data1": { "name": "Test1", "count": 0, "amount": 0, "amtData": [ 0,0,0,0 ], "cntData": [ 0,0,0,0 ], "color": "#FF0F00" }, "data2": { ...

Why is it that consolidating all my jQuery plugins into one file is ineffective?

Prior to this, I included the following scripts: <script type="text/javascript" src="{{MEDIA_URL}}js/plugins/json2.js"></script> <script type="text/javascript" src="{{MEDIA_URL}}js/plugins/jquery-msdropdown/js/jquery.dd.js"></script&g ...