2

I tried to install grunt on Ubuntu 14.04 and wrote grunt serve

I am getting this error.

Warning: Task "serve" not found. Use --force to continue.

Aborted due to warnings.

  1. I have Gruntfile.js in my project folder next to package.json file
  2. When I write grunt --version I get:

         grunt-cli v0.1.13
         grunt v0.4.5
    
  3. I tried @Tom P's answer:

  4. I have read Grunt documentation

  5. All Installations done through sudo

  6. Tried this as well

This is the Gruntfile sample code I took from Official Grunt documentation.

 module.exports = function(grunt) {
      // Project configuration.
      grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),
      uglify: {
                 options: {
                 banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
                 src: 'src/<%= pkg.name %>.js',
                 dest: 'build/<%= pkg.name %>.min.js'
      }
    }
});

    // Load the plugin that provides the "uglify" task.
    grunt.loadNpmTasks('grunt-contrib-uglify');

   // Default task(s).
   grunt.registerTask('default', ['uglify']);

 };

   module.exports = function(grunt) {
    // Project configuration.
    grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    serve:{
              options: {
                      port: 8000
              }
    },
    uglify: {
            options: {
              banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            build: {
              src: 'src/<%= pkg.name %>.js',
              dest: 'build/<%= pkg.name %>.min.js'
            },
          }
     });

   // Load the plugin that provides the "uglify" task.
   grunt.loadNpmTasks('grunt-contrib-uglify');
   grunt.loadNpmTasks('grunt-serve');

  // Default task(s).
  grunt.registerTask('default', ['uglify']);

}

Community
  • 1
  • 1
  • 1
    What's the anonymous downvote for? Not very helpful to a new user. – Armand May 25 '15 at 08:14
  • Then the Gruntfile that is loaded does not contain the task `serve`. If your Gruntfile does include a `serve` task, then you might run grunt in the wrong directory. You should at least show the part of the Gruntfile where you define that task. – t.niese May 25 '15 at 08:16
  • @I_AM_NOT_A_CODER if you can share the contents of your `Gruntfile.js` it might help diagnose the problem – Armand May 25 '15 at 08:17
  • might be useful to add your gruntfile, to see what your `serve` task is supposed to do. – Sze-Hung Daniel Tsui May 25 '15 at 08:19
  • I want to know that you have to copy this code from the documentation for creating a gruntfile? can't we do like what we do for package.json by writing npm-init. – I_AM_NOT_A_CODER May 25 '15 at 08:29
  • You haven't registered for the `serve` task. So it is not running. Executing `grunt` will run your default task, which will in turn run uglify task and will uglify the files in specified location. – Saba May 25 '15 at 08:32
  • There are various npm packages which you can view as a library with built-in functionalities. So you need to write tasks to make use of it. And so you need to include the npm package before use `grunt.loadNpmTasks('grunt-contrib-uglify');` . Everytime you cannot copy the same code. You have to build or tailor the gruntfile according to your requirement. – Saba May 25 '15 at 08:35
  • I have to install the required modules and find the Gruntfile inside my node_modules? – I_AM_NOT_A_CODER May 25 '15 at 08:52
  • But if you tried Tom P's answer, why is grunt installed globally? It should be installed within you node project. – cbass May 25 '15 at 08:56
  • I was getting errors, I have modified the Gruntfile, the server is up but auto reload is not working. Looking into it. – I_AM_NOT_A_CODER May 25 '15 at 09:29
  • You return two different functions from `gruntfile.js`. The first one which is probably being executed doesn't have `serve` task – zaynetro May 25 '15 at 12:58

0 Answers0