Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt required config property missing

setting up a new project that will have multiple grunt tasks that I want to load from task files.

when running my first task, 'core' which is supposed to build the core css for the site, I'm getting an error that I can't seem to resolve. been doing some googling and not finding this specific issue. any issues with the same error message usually were the result of a typo or misplaced curly braces on the part of the OP. Not sure that's the case here, but perhaps someone else sees what I'm obviously not seeing.

Gruntfile.js

module.exports = function(grunt) {

    grunt.initConfig({
        pkg: require('./package.json')
    });

    grunt.loadTasks('grunt-tasks');

};

grunt-tasks/grunt-core.js

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-sass');
    grunt.config('core', {
        sass : {
            options : {
                sourceMap : true,
                includePaths : 'node_modules/bootstrap-sass/assets/stylesheets'
            },
            dist : {
                files : {
                    'main.css' : 'main.scss'
                }
            }
        }
    });
    grunt.registerTask('core', ['sass:dist']);
};

error:

$ grunt core
Running "sass:dist" (sass) task
Verifying property sass.dist exists in config...ERROR
>> Unable to process task.
Warning: Required config property "sass.dist" missing. Use --force to continue.

Aborted due to warnings.

I've tried a few different things. If I change the registerTask to this:

grunt.registerTask('core', ['sass']);

I get this error:

$ grunt core
>> No "sass" targets found.
Warning: Task "sass" failed. Use --force to continue.

Aborted due to warnings.

not sure if this is relevant, but here is package.json and some specs on the system I'm using.

Mac OSX Yosemite
node version v5.10.1
npm 3.8.3

package.json

{
  "name": "TEST",
  "version": "1.0.0",
  "description": "test test test",
  "main": "Gruntfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/path/to/repo"
  },
  "author": "me <[email protected]>",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/path/to/repo/issues"
  },
  "homepage": "https://github.com/path/to/repo",
  "devDependencies": {
    "angular": "^1.5.5",
    "bootstrap-sass": "^3.3.6",
    "grunt": "^1.0.1",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-uglify": "^1.0.1",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-sass": "^1.1.0",
    "jquery": "^2.2.3",
    "sass-lint": "^1.5.1"
  },
  "dependencies": {
    "jquery": "^2.2.3"
  }
}
like image 214
keith73 Avatar asked Apr 25 '16 18:04

keith73


People also ask

What are the grunt task properties?

While a task is running, Grunt exposes many task-specific utility properties and methods inside the task function via the this object. This same object is also exposed as grunt.task.current for use in templates, eg. the property this.name is also available as grunt.task.current.name.

How do I access the config object in a Gruntfile?

The specified configObject is used by tasks and can be accessed using the grunt.config method. Nearly every project's Gruntfile will call this method. Note that any specified <% %> template strings will be processed when config data is retrieved.

What happens if one of the required Config Properties is missing?

Fail the current task if one or more required config properties is missing. One or more string or array config properties may be specified. this .requiresConfig (prop [, prop [, ...]]) See the grunt.config documentation for more information about config properties.

How do I add files to a grunt task?

A task user can just specify files per the Configuring tasks guide, and Grunt will handle all the details. Your task should iterate over the this.files array, utilizing the src and dest properties of each object in that array. The this.files property will always be an array.


1 Answers

Looks like it was user error on my part.

in the task file, I had grunt.config(), but I should have had grunt.initConfig()

var taskConfig = {
    sass : {
        options : {
            sourceMap : true,
            includePaths : 'node_modules/bootstrap-sass/assets/stylesheets'
        },
        dist : {
            files : {
                'main.css' : 'main.scss'
            }
        }
    },
    concat : {
        core : {
            src : ['node_modules/jquery/dist/jquery.js', 'js/main.js'],
            dest : "../dev/js/main.js"
        }
    }
};

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-sass');
    grunt.initConfig(taskConfig);
    grunt.registerTask('core', ['concat:core','sass']);
};
like image 94
keith73 Avatar answered Oct 14 '22 03:10

keith73