'grunt' command doesn't do anything

2019-04-19 14:05发布

问题:

I'm following the grunt getting started guide for my new app, but I'm having some trouble.

This is my Gruntfile.js

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {,
      build: {
        src: 'js/*.js',
        dest: 'build/*.min.js'
      }
    }
  });

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

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

};

This is my package.json

{
  "name": "My App",
  "version": "0.0.0",
  "description": "",
  "author": "",
  "license": "N/A",
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-jshint": "~0.8.0",
    "grunt-contrib-uglify": "~0.2.7"
  }
}

I have the grunt-cli package installed and I've run npm install to get a local version of grunt and the contrib libraries.

But when I run either grunt or grunt uglify nothing happens.

$ grunt
$ grunt uglify
$

Any idea what I have missed or what could cause this behaviour?

EDIT: I just installed mocha too and I get the same issue with that: no output. Maybe there is a problem with my node or npm installation

回答1:

So it looks like this was an environment setup issue. I had an ubuntu package called node installed as well as nodejs which was preventing the packages installed through npm from working. Running the following command fixed the issue.

sudo apt-get --purge remove node


回答2:

I had the same problem. Grunt was not responding. No output was being displayed. Removing node and installing nodejs-legacy worked for me.

Removing node by:

sudo apt-get --purge remove node

and installing legacy by:

sudo apt-get install nodejs-legacy