กำลังโหลดงาน Gruntfile.js ข้อผิดพลาดขณะเรียกใช้ 'grunt'

ฉันยังใหม่กับโลก Grunt

หลังจากติดตั้ง grunt-cli และการอ้างอิงทั้งหมด นี่คือของฉัน : 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']);

};

ผลลัพธ์

ตอนนี้ในส่วนการทดสอบ ฉันลองเรียกใช้ grunt แล้วฉันได้รับ:

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

Aborted due to warnings.

ใครช่วยบอกฉันหน่อยว่าฉันทำอะไรผิดที่นี่?


comment
มันไม่เข้าใจ grunt.loadNpmTasksNpmTasks มันควรจะเป็น grunt.loadNpmTasks เหมือนครั้งก่อน ฉันคิดว่ามันแค่สับสน   -  person Andy    schedule 11.05.2015


คำตอบ (2)


ดูเหมือนว่าเป้าหมาย default ไม่ได้ถูกสร้างขึ้นอย่างถูกต้องเนื่องจากการพิมพ์ผิด ลองเปลี่ยนชื่อ

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

to

grunt.loadNpmTasks('grunt-contrib-watch');
person Daniel Imms    schedule 11.05.2015
comment
มีความแตกต่างระหว่างพวกเขาบ้างไหม? - person cyb3rZ; 11.05.2015
comment
วิธีแรกไม่ใช่วิธีฮึดฮัดที่ถูกต้อง - person Andy; 11.05.2015
comment
คำถามสั้นๆ ดูเหมือนว่าฉันจะหยุดพูด Running Watch task Waiting ... - person cyb3rZ; 11.05.2015
comment
grunt-contrib-watch มีไว้เพื่อทำเช่นนั้น โดยบอกว่าโปรแกรมกำลังรอ ฟัง (ดู) สำหรับการเปลี่ยนแปลง - person Daniel Imms; 11.05.2015
comment
มีวิธีกำหนดค่านาฬิกาฮึดฮัดของฉันให้ไม่ทำอะไรเลยหรือไม่หากไม่มีอะไรเปลี่ยนแปลง? - person cyb3rZ; 11.05.2015
comment
หากคุณต้องการให้เบราว์เซอร์ของคุณอัปเดตเมื่อคุณเปลี่ยนไฟล์ css หรือ js ให้ปล่อยไว้ มันจะไม่ทำอะไรเลยถ้าไม่มีอะไรเปลี่ยนแปลง ฉันไม่แน่ใจว่าคำถามของคุณคืออะไรจริงๆ - person Andy; 11.05.2015
comment
นั่นคือวิธีการทำงานของนาฬิกา โปรแกรมจะต้องทำงานอย่างต่อเนื่องเพื่อรับฟังการเปลี่ยนแปลงเพื่อเผยแพร่การเปลี่ยนแปลง - person Daniel Imms; 11.05.2015

ประสบปัญหาที่คล้ายกันและลองใช้คำสั่งด้านล่างซึ่งติดตั้งโมดูลโหนดของคุณซึ่งแก้ไขปัญหาให้ฉันได้:

npm install --unsafe-perm
person sid7747    schedule 30.11.2018