【问题标题】:Loading "Gruntfile.js" tasks...ERROR while running `grunt`加载“Gruntfile.js”任务...运行`grunt`时出错
【发布时间】:2015-05-11 15:21:47
【问题描述】:

我是 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.

谁能告诉我我在这里做错了什么?

【问题讨论】:

  • 看不懂grunt.loadNpmTasksNpmTasks。应该是grunt.loadNpmTasks 和上一个一样。我认为这只是混乱。

标签: javascript gruntjs grunt-contrib-watch grunt-contrib-concat


【解决方案1】:

由于拼写错误,default 目标似乎没有正确创建。尝试重命名

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

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

【讨论】:

  • 它们之间有什么区别吗?
  • 第一个不是有效的 grunt 方法。
  • 快速提问,我似乎停不下来说Running Watch task Waiting ...
  • grunt-contrib-watch 的意思是这样做的,它表示程序正在等待,监听(观察)变化。
  • 有没有办法让我的 grunt watch 在没有任何改变的情况下什么也不做?
【解决方案2】:

遇到过类似的问题,并尝试了以下安装节点模块的命令,这为我解决了问题:

npm install --unsafe-perm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 2018-11-21
    • 2020-04-22
    • 2017-09-08
    • 2016-05-30
    • 1970-01-01
    • 2015-07-25
    相关资源
    最近更新 更多