grunt task undefined not found - javascript

I'm fairly new to Grunt and trying to run a custom task using grunt-protractor-coverage plugin but I get the error
Warning: Task "undefined" not found. Use --force to continue.
My script is as follows.
module.exports = function(grunt) {
grunt.registerTask('test', 'Log some stuff.', function() {
console.log('Logging some stuff...');
});
grunt.initConfig({
instrument: {
files: 'server/**/*.js',
options: {
lazy: true,
basePath: "instrumented"
}
}
});
grunt.loadNpmTasks('grunt-protractor-coverage');
grunt.registerTask('instrument');
// Default task(s)
grunt.registerTask('default', ['instrument']);
};

I had this issue before, and solved it by updating grunt. Would be a good first step to try:
npm --global update grunt-cli

Related

Grunt File Blocks `Required config property ... missing`

I cannot seem to get fileblocks running. Every time I run grunt I get this error message:
Running "wiredep:app" (wiredep) task
Running "fileblocks:dev" (fileblocks) task
Verifying property fileblocks.dev exists in config...ERROR
>> Unable to process task.
Warning: Required config property "fileblocks.dev" missing. Use --force to continue.
Aborted due to warnings.
I have a modular setup for integrating the various tasks executed by Grunt. I have installed file-blocks by running npm install --save-dev grunt-file-blocks and my Gruntfile.js is:
module.exports = function(grunt) {
grunt.initConfig({
pkg: require('./package.json')
});
grunt.loadTasks('grunt-tasks');
grunt.registerTask('default', ['wiredep', 'fileblocks:dev']);
};
Here's my grunt-tasks/fileblocks.js:
module.exports = function(grunt) {
grunt.initConfig({
fileblocks: {
dev: {
src: 'app/*.html',
blocks: {
'css': {
src: 'app/*.css'
},
'js': {
src: 'src/*.js'
}
}
}
}
});
grunt.loadNpmTasks('grunt-file-blocks');
};
So, I expect fileblock:dev to run the fileblocks task dev that I've defined, but I get the aforementioned error. Help!

new to grunt - warning: task "concat, uglify" not found

As the title says I'm new to Grunt. I am following a tutorial located at: http://24ways.org/2013/grunt-is-not-weird-and-hard/. It is an older tutorial but most seems to work the same. I have installed "grunt-contrib-concat" and "grunt-contrib-uglify" and can run both individually. But when I run grunt, I get the following error: Warning: Task "concat, uglify" not found. Use --force to continue. Aborted due to errors. I've been looking around and can't seem to figure it out. My files are as follows:
Gruntfile.js:
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'js/libs/*.js', // All JS in the libs folder
'js/controls.js', // This specific file
],
dest: 'dist/built.js',
}
},
uglify: {
build: {
src: 'js/build/production.js',
dest: 'js/build/production.min.js',
}
},
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
// 4. Where we tell Grunt what to do when we type 'grunt' into the terminal.
grunt.registerTask('default', ['concat, uglify']);
};
package.json:
{
"name": "grunt_libsass_example-project",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.1",
"grunt-contrib-uglify": "^0.9.1"
}
}
Your passing in only one string for the registerTask task list. It should be a array with a list of strings like:
grunt.registerTask('default', ['concat', 'uglify']);
You're getting that error because it's looking for a task named 'concat, uglify'.
I had to run:
npm install grunt-contrib-uglify --save-dev

Grunt: Task "grunt-bower" not found

I want to install package grunt-bower for my grunt by using npm install grunt-bower --save. After I install, I see package grunt-bower inside node_modules. Here is my gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
bower: {
dev: {
dest: 'public',
js_dest: 'public/javascripts',
css_dest: 'public/stylesheets'
}
},
watch: {
source: {
files: ['sass/**/*.scss', 'views/**/*.jade'],
tasks: ['sass'],
options: {
livereload: true, // needed to run LiveReload
}
}
}
});
grunt.loadNpmTasks('grunt-bower');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['grunt-bower']);
};
I have register this as on official page : grunt.loadNpmTasks('grunt-bower'); But when I run grunt command, I meet this error:
Warning: Task "grunt-bower" not found. Use --force to continue.
I don't know why. Does I do something wrong ? Please tell me.
Thanks :)
You've defined the task you want to run as bower and not grunt-bower therefore,
grunt.registerTask('default', ['grunt-bower']);
should be
grunt.registerTask('default', ['bower']);

PhantomJS failed to load your page. Use --force to continue

I am trying to run test with grunt-contrib-jasmine trough command line "grunt jasmine", but its fails giving the warning : "PhantomJS failed to load your page. Use --force to continue."...
base.spec.js:
describe('Namespace',function(){
it('Provides the global *** object',function(){
expect(***).to.be.an('object');
expect(***).to.include.keys('App','Templates');
});
});
gruntfile.js including this:
jasmine : {
src : ['apps/<%=target%>/js/**/*.js'],
options : {
host : 'http://127.0.0.1:5000',
specs : 'tests/<%=target%>/**/*spec.js',
}
},
.
.
.
grunt.loadNpmTasks('grunt-contrib-jasmine');
Can't understand what is wrong...
Please help, Thanks in advance...
In gruntfile.js make your src: 'apps/<%=target%>/js/**/FileName',
(remove the .js after filename)
Add this before jasmine:
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
connect: {
test : {
port : 8000,
base: 'test'
}
},
set a default task so it can perform connection and then execute:
grunt.registerTask('default', ['connect','jasmine']);
if it yet fails then try doing grunt jasmine --force to know where its failing

grunt watch executes tasks multiple times

I've the following Grunfile.js File:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'css/build/style.css': 'css/style.scss'
}
}
},
watch: {
stylesheets: {
files: ['css/*.scss'],
tasks: ['newer:sass']
}
}
});
// Load the plugin that compiles sass
grunt.loadNpmTasks('grunt-contrib-sass');
// watch for, and run grunt if files change
grunt.loadNpmTasks('grunt-contrib-watch');
// Plugin for Grunt tasks to run with newer files only.
grunt.loadNpmTasks('grunt-newer');
// Grunt Tasks:
grunt.registerTask('default', ['newer:sass']);
};
After running grunt watch and saving my scss File, the console output is the following:
Running "watch" task
Waiting...
>> File "css\style.scss" changed.
Running "newer:sass" (newer) task
Running "newer:sass:dist" (newer) task
Running "sass:dist" (sass) task
File css/build/style.css created.
Running "newer-postrun:sass:dist:1:D:\xampp\htdocs\grunt-test\node_modules\grunt-newer\.cache" (newer-postrun) task
Done, without errors.
The problem is, the .scss file is compiled every time. Even if there was no change.
I don't understand why grunt is running 3 tasks (newer:sass, newer:sass:dist, sass:dist), instead of only running the task defined under watch (newer:sass).
Hope someone has an idea to fix this. :)
I'm not positive this is the problem, but try specifying that you don't want to run all of sass, just sass:dist. So try: grunt.registerTask('default', ['newer:sass:dist']);

Categories

Resources