Unable to locate a resolution for the error message "Warning: Task "uglify" not found"

Below is the content of my Gruntfile.js:

module.exports = function(grunt) {

  require('load-grunt-tasks')(grunt);

  grunt.initConfig({

    uglify: {
      start: {
        files: {
          'js/script.min.js': ['js/script.js'],
        }
      }
    },

    imagemin: {
      build: {
        options: {
          optimizationLevel: 3
        },
        files: [{
          expand: true,
          src: ['img/sprite_svg/*.svg'],
        }]
      }
    },

    svgstore: {
      options: {
        includeTitleElement: false,
        svg: {
          style: 'display:none',
        },
        cleanup: [
          'fill',
        ],
      },
      default : {
        files: {
          'img/sprite.svg': ['img/sprite_svg/*.svg'],
        },
      },
    },

    watch: {
      livereload: {
        options: { livereload: true },
        files: ['build/**/*'],
      },
      scripts: {
        files: ['js/script.js'],
        tasks: ['js'],
        options: {
          spawn: false
        },
      },
      images: {
        files: [
          'img/sprite_svg/*.svg'
        ],
        tasks: ['img'],
        options: {
          spawn: false
        },
      },
      html: {
        files: ['./index.html'],
        // tasks: ['html'],
        options: {
          spawn: false
        },
      },
    },

    browserSync: {
      dev: {
        bsFiles: {
          src : [
            'img/sprite.svg',
            './index.html',
          ]
        },
        options: {
          watchTask: true,
          server: {
            baseDir: "./",
          },
          startPath: "index.html",
          ghostMode: {
            clicks: true,
            forms: true,
            scroll: false
          }
        }
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-imagemin');

  grunt.registerTask('default', [
    'js',
    'img',
    'browserSync',
    'watch'
  ]);

  grunt.registerTask('js', [
    'uglify'
  ]);

  grunt.registerTask('img', [
    'imagemin',
    'svgstore'
  ]);

};

I have installed both the uglify and imagemin npm packages, but I am encountering an error: Warning: Task "uglify" not found.

This issue arose after adding svgstore to the configuration, and I suspect it may be a syntax error. As a beginner in using Grunt, I'm unsure about what is causing this problem. Any assistance or guidance would be highly appreciated.

Answer №1

Can you tell me what the package.json file contains?

"load-grunt-tasks" automatically retrieves packages from both "dependencies" and "devDependencies" in the package.json, eliminating the need to manually use "grunt.loadNpmTasks".

Additionally, it is recommended to install "grunt-contrib-uglify" instead of just "uglify".

Answer №2

There are extra commas present after the last item in two arrays

grunt.registerTask('js', [
  'uglify' // <-- please remove this comma 
]);

grunt.registerTask('img', [
  'imagemin',
  'svgstore' // <-- it's best to remove this comma as well
]);

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

A database table named after a pair of digits

My database tables are named "30" and "kev." When I query the table named "30," I receive the following error message: Warning: Invalid argument supplied for foreach() in # on line 94 However, when I query the kev table, I do get the desired results. B ...

Set cookies can be accessed within the response object

Before reaching the route, I checked and set a couple of cookies in the middleware. However, when attempting to access these cookies within the handler after hitting the route, I realized that the response object does not provide an accessor for accessing ...

Error 3: The Incompatibility Between Socket.io and Express

Running app.js does not produce any errors, but I am unable to trigger a JavaScript prompt for username. Only chat.html is loading correctly while everything else seems to be malfunctioning. I suspect the issue may lie in: The line io = require('sock ...

Parsing HTML using PHP's Simple HTML DOM Parser

I'm having trouble extracting specific information from HTML code using a DOM parser. <div id="posts"> <div class="post"> <div class="user">me:</div> <div class="post">I am an apple</div> &l ...

What is the reason behind the overflow in the HTML body?

I am currently honing my skills in front-end development by attempting to replicate the functionality of . Everything seems to be working fine, except for the fact that there is an overflow issue identified within the <body> element when inspecting w ...

What is the best way to deploy a React build using Express.js on Elastic Beanstalk?

I'm faced with a challenge in getting elastic beanstalk to properly serve React from Node.js. While everything works fine locally, I'm struggling to configure the path in elastic beanstalk to serve react. In my project, I have an express app.js ...

Using Nodemon and Express Server with BrowserSync

Struggling to get Browser Sync and Nodemon to play nice with my Express server. I've experimented with all sorts of setups but can't seem to get it right. The Express server is running on port 5000 just fine, nodemon kicks in when there are chan ...

Having trouble locating and interacting with the textarea element in Salesforce using Selenium Webdriver

Encountering an issue with the Selenium Webdriver where it throws an error stating that the element is not visible and cannot be interacted with when attempting to access a textarea. 1. The textarea is located within a pop-up window, which can be accessed ...

Troubleshooting the onExited callback issue with Popover component in Material UI

<Popover key={element.name} classes={{ paper: classes.paper }} open={open} anchorEl={this.myRef.current} anchorOrigin={{ vertical: ' ...

Creating customized JQuery UI tabs to perfectly accommodate the available horizontal space

Can JQuery UI Tabs be modified to fill the horizontal space and stack to the left? In order to achieve this, could we consider using a markup like the one below: <table width="100%"> <tr> <td> ...content... </td> ...

Sideways movement of a single line within a table

Would you please help with a challenge I'm facing? I want to create a horizontally scrollable row that spans 100% of the page width without overflowing on top of the background image and while keeping the header text in focus. This is what I have att ...

Verify whether the current location is within the circle

I am conducting a test to determine if my current location falls within a given radius of 300m. If it does, return true; otherwise return false. Below is the code I am currently using: <body> <button onclick="getLocation()"> ...

What could be causing the issue with Hindi text not displaying properly on Safari?

I'm having trouble with displaying Hindi text on my website. I tried pasting the text in a new file and it worked, so why is it not loading correctly in this case? The Hindi script is within the second span with the class word w2. "use strict"; le ...

Display a block by using the focus() method

My objective is : To display a popin when the user clicks on a button To hide the popin when the user clicks elsewhere I previously implemented this solution successfully: Use jQuery to hide a DIV when the user clicks outside of it However, I wanted to ...

Using Python to access files

I have developed a system that allows me to load image files from HTML. However, after selecting a file and loading it from the front end, I am in need of a Python API to read the selected image file. How can I establish a connection between Python and HTM ...

"The issue with Firebase Realtime Database arises when using NextJS after the build process, resulting in an error of 'Maximum call

Utilizing Firebase Realtime Database with Next.js for the backend implementation has been my approach. I have included the code snippet below. However, it seems to function properly only in a local environment, failing when deployed to production. I inten ...

Conceal a div element after redirecting to a different HTML page

I have a dilemma with my two HTML pages - index.html and register.html. I am trying to navigate from index.html to register.html, but I want to skip the select region step and go straight to the login page. Here's the code snippet I've been attem ...

Position Bootstrap Modal in the center horizontally

I am working on an Angular project and struggling to center my Bootstrap 3 Modal horizontally on the screen. Despite trying various solutions like using text-align: center and align = "center", I have been unsuccessful. Can someone guide me on how to prope ...

Exploring different preact.js configurations to set up a simple environment for debugging the source code

Exploring the depths of preact.js has proven to be quite a challenge. Despite successfully setting up the framework using webpack build from the preact-boilerplate setup, I am encountering difficulty in accessing and intercepting the code for debugging pur ...

The overlay is larger in size compared to the video positioned beneath it

I'm having trouble placing a video underneath a purple layer as the overlay isn't aligning properly with my video. After removing the background-size: cover; in the home section, it appears like this: .videoContainer {} .videoContainer .over ...