admin管理员组

文章数量:1323023

I'm new to the Grunt world.

After installing grunt-cli, and all the dependencies, here is my : Gruntfile.js

/*
        Grunt installation:
        -------------------
            npm install -g grunt-cli
            npm install -g grunt-init
            npm init (creates a `package.json` file)

        Project Dependencies:
        ---------------------
            npm install grunt --save-dev
            npm install grunt-contrib-concat --save-dev
            npm install grunt-contrib-watch --save-dev



        Example Usage:
        --------------
            grunt -v
            grunt release -v

*/


module.exports = function(grunt) {
    "use strict";

    grunt.initConfig({

        concat: {

            js: {
                src: ['js/bootstrap.min.js', 'js/jquery-1.10.2.min.js'],
                dest: 'build/js/scripts.js'
            },

            css: {
                src: ['css/bootstrap.min.css', 'css/font-awesome.min.css'],
                dest: 'build/css/styles.css'
            }
        },

        watch: {

            js: {
                files: ['js/**/*.js'],
                task: ['concat:js']
            },

            css: {
                files: ['css/**/*.css'],
                task: ['concat:css']
            }
        }

    });

    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasksNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', ['concat', 'watch']);

};

Result

Now the testing part, I tried run grunt, I kept getting :

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

Can someone please tell me what did I do wrong here ?

I'm new to the Grunt world.

After installing grunt-cli, and all the dependencies, here is my : Gruntfile.js

/*
        Grunt installation:
        -------------------
            npm install -g grunt-cli
            npm install -g grunt-init
            npm init (creates a `package.json` file)

        Project Dependencies:
        ---------------------
            npm install grunt --save-dev
            npm install grunt-contrib-concat --save-dev
            npm install grunt-contrib-watch --save-dev



        Example Usage:
        --------------
            grunt -v
            grunt release -v

*/


module.exports = function(grunt) {
    "use strict";

    grunt.initConfig({

        concat: {

            js: {
                src: ['js/bootstrap.min.js', 'js/jquery-1.10.2.min.js'],
                dest: 'build/js/scripts.js'
            },

            css: {
                src: ['css/bootstrap.min.css', 'css/font-awesome.min.css'],
                dest: 'build/css/styles.css'
            }
        },

        watch: {

            js: {
                files: ['js/**/*.js'],
                task: ['concat:js']
            },

            css: {
                files: ['css/**/*.css'],
                task: ['concat:css']
            }
        }

    });

    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasksNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', ['concat', 'watch']);

};

Result

Now the testing part, I tried run grunt, I kept getting :

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

Can someone please tell me what did I do wrong here ?

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked May 11, 2015 at 15:21 code-8code-8 58.8k120 gold badges390 silver badges666 bronze badges 1
  • It doesn't understand grunt.loadNpmTasksNpmTasks. It should be grunt.loadNpmTasks like the previous one. I think it's just confused. – Andy Commented May 11, 2015 at 15:26
Add a ment  | 

2 Answers 2

Reset to default 3

It looks like the default target is not being created properly due to a typo. Try renaming

grunt.loadNpmTasksNpmTasks('grunt-contrib-watch');

to

grunt.loadNpmTasks('grunt-contrib-watch');

Have faced similar issues and tried below mand where your node modules is installed which resolved issue for me:

npm install --unsafe-perm

本文标签: javascriptLoading quotGruntfilejsquot tasksERROR while running gruntStack Overflow