The reason behind gulp-uglify not functioning properly when implementing ES6 syntax in AngularJS

Currently, I am attempting to compress all of my AngularJS files using gulp-uglify. However, I have run into a roadblock due to the fact that I have utilized ES6 syntax in my project, particularly arrow function.

Upon trying to minify a js file with this code:

gulp.task('minify-scripts', function() {
  return gulp.src(jsFiles)
    .pipe(concat('scripts.js'))
    .pipe(gulp.dest(jsDest))
    .pipe(rename('scripts.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest(jsDest));
});

I encountered an error when trying to minify the following ES6 code snippet:

apiService.fetchAccessToken($scope.body).then((response) => {

The error displayed was:

events.js:160 throw er; // Unhandled 'error' event

Interestingly, switching back to traditional code instead of ES6 code like so:

apiService.fetchAccessToken($scope.body).then(function(response) {

resolved the issue. Can anyone guide me on what steps I may have overlooked within the gulp configuration for minifying es6 code?

Answer №1

As per the information provided in the readme on GitHub for gulp-uglify, it is recommended to utilize uglify-es for ES6 compatibility.

// It could either be a git checkout // or another module (like uglify-es for ES6 compatibility)

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

Stop the form from refreshing the page after submitting a post request to the backend API

I am facing an issue with my React front end and Express back end integration. I have a form in my front end that sends data to the API using two buttons - Submit and Close. The Close button works perfectly by closing the overlay without leaving the page, ...

Understanding the scope within a .when .done function in jQuery

I'm currently grappling with accessing a variable from within a .when.done function. Take a look at this illustrative example: var colviews = { 1: true, 2: true, 3: false } $.when( $.getScript( "/mckinney_images/jquery.tablesorter. ...

Is there a intentional way to cause my node.js server to crash?

Is there a way to intentionally crash my node.js server? I want to trigger this action when specific fatal errors occur in order to immediately bring them to my attention for fixing. I came across a post about this topic here, but I am not interested in u ...

What is the best method for filtering a dynamic object in Express.js?

Utilizing express for my REST API, I am looking to implement some filtering on my Posts based on req.query. Within the post structure, I have integrated a dynamic Object called options. Here is an example of my post structure: { "category": [ ...

Images in HTML are misaligned after fetching data from the JSON file

Recently, I've been working on a website dedicated to the League of Legends game. The main feature of this site is that it utilizes the Riot API to fetch data about the mastery tree and then showcases the images related to it. Everything was going smo ...

executing a controller method in AngularJS

Looking to trigger a controller function from a directive tag. Check out this demo: https://jsfiddle.net/6qqfv61k/ When the 'Export to Excel' button is clicked, I need to call the dataToExport() function from appCtrl since the data is ready for ...

Calling Ajax to Flask for fetching MySQL query results

My goal is to populate a drop-down list in my HTML using AJAX by calling my flask app app.py from app.js. I am attempting to load the data when the page initially loads and triggering the AJAX within $(document).ready as shown below: Here is the content o ...

Does this sample Redux reducer from the latest Pro React 16 publication pass muster?

Currently, I am immersing myself in the world of React and Redux while delving into "Pro React 16" by Adam Freeman. In Chapter 5, there is an interesting reducer example that deals with actions related to a shopping cart. Here's a snippet: import { A ...

Submit JSON data through an HTML form

Currently, I am working with React on the front-end and expressJs for the server. I have a JavaScript Object containing data that needs to be sent to the server. In order to achieve this, I use JSON.stringify to convert the data and then store it within a ...

choosing from dropdown menu items

Learn HTML <table> <tr> <td>ENTER PRINCIPLE AMOUNT</td> <td><input type="text" name="principle" size="7"></td> </tr> <tr> <td>ENTER RATE OF INTEREST</td> <td><input type="text" na ...

Utilize formData to upload an image to a database with ajax

I'm struggling with the process of uploading an image from an HTML form. The goal is for the form to send the image name along with other data to a PHP page. Instead of using the serialized function, I opted for formData as it has the capability to h ...

ReactTooltip.hide does not immediately conceal the tooltip

I'm currently working on implementing a tooltip in my React project using the react-tooltip library. I want to include a close button in the tooltip, but I'm facing an issue with hiding it effectively. As per the instructions provided in the docu ...

Tips for embedding query values within a mongoose query

I have a database in MongoDB that contains an array with company names. I need to remove a specific element from the array based on its position. So, I crafted a query to achieve this. { company: [ {name: "exist"}, {name: "cool"}, {name: "h ...

Using ng-transclude directive in AngularJS for input values

My goal is to develop a directive that includes the ng-transclude value in the input field's value attribute within an HTML template: The directive I have created: module.directive('editInput', function(){ return { restrict: &a ...

Inquiry about how TypeScript handles object property references when passed into functions

As a newcomer to TypeScript, I am exploring the creation of a range slider with dual handles using D3.js. I have developed a simple class for managing the slider objects: export class VerticalRangeSlider{ private sliderContainer: d3.Selection<SVGG ...

Plaid webhook failing to activate

I've been struggling to set up Plaid transaction webhooks in an api, as I can't seem to get any webhooks to trigger. I followed the plaid quickstart code and included the webhook parameter: Plaid.create({ apiVersion: "v2", clientName: ...

Determining the coordinates of an object post-rotation using three.js

After applying a rotation to my object, I want to retrieve its new position in order to move my camera there and set the lookAt vector accordingly. Can anyone provide guidance on how to achieve this? Thanks in advance! ...

Ways to boost heap capacity in Corb2 for MarkLogic

I encountered a challenge while running my custom deletion framework on a massive dataset. When attempting to execute Corb2, I started receiving the warning below and occasionally even encountered errors due to insufficient memory. WARNING: Slow receive! C ...

Parse multiple JSON files, manipulate their contents, and store the updated data

I'm currently working on implementing this functionality using Gulp. Locate and access all files with the extension .json within a designated directory, including any subdirectories. Perform modifications to the files in some manner, such as adding ...

Exploring the depths of ES6 with cascading promises

Currently grappling with a dilemma while working with promises - it's more of a Best Practice question. I have a function that returns a promise resolving into a validated object: validate(req.body, bodyValidationSchema) Another function creates an ...