Grunt is not defined - gruntjs

Just Getting started with grunt, and when I run grunt I get this error
Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: grunt is not defined
This is my Gruntfile.js
module.exports = function(grunt){
'use strict';
};

I had it suddenly happen to me,
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
sass: {
dist: {
files: {
'style.css': 'style.scss'
},
options: {
includePaths: ['css/'],
outputStyle: 'nested'
}
}
},
});
grunt.loadNpmTasks('grunt-sass');
grunt.registerTask('sass', ['sass']);
};
Make sure the loadNpmTasks and registerTask commands are inside the module.export, if they're outside of the scope of that closure grunt won't be defined, so it fails

Not entirely sure why, but this resolved that issue:
'use strict';
module.exports = function(grunt){
};

I too saw many "grunt not defined" error messages on my terminal.
I grabbed another gruntfile.js from the same directory where I had Node and NPM installed, and replaced the boilerplate gruntfile.js with the other gruntfile.js.
Now, I call Grunt and it works.

I had trailing commas in my gruntfile code which was throwing that error. Thank you ReSharper. Hope this helps someone.
pkg: grunt.file.readJSON('package.json'),
ngAnnotate: {
options: {
singleQuotes: true
},
FFApp: {
files: {
'Scripts/Angular-Annotated/Annotated.js': ['Scripts/Angular/**/*js']
}
, (< deleted this)
}
,(< and this one)
},

Related

Warning: Task "taskname" not found. Use --force to continue while running grunt

I'm trying to convert .css files to .sass files using 'grunt-sass-convert' npm module.
'Gruntfile.js' for the same is as follows:
'use strict';
module.exports = function(grunt){
grunt.loadNpmTasks('grunt-sass-convert');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Sass: {
options: {
// command line options here
style: 'expanded',
from: 'css',
to: 'sass'
},
files: {
// Target-specific file lists and/or options go here.
cwd: 'style',
src: '*.css',
filePrefix: '_',
dest: 'sass/'
}
}
});
grunt.registerTask('default',['Sass']);
};
I referred grunt-sass-convert npm module documentation for writing the GruntFile.js file.
While running the grunt command in cmd, I'm getting the following error:
Warning: Task "Sass" not found. Use --force to continue.
Aborted due to warnings.
I went through so many stackoverflow links regarding the same but I'm unable to fix it and All I understood that there's some error in .js file that's why it's throwing the error.
Directory structure I'm using is as here
Thanks..!!
I guess this would help you -
'use strict';
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Sass: {
options: {
// command line options here
style: 'expanded',
from: 'css',
to: 'sass'
},
files: {
// Target-specific file lists and/or options go here.
cwd: 'style',
src: '*.css',
file_prefix: '_',
dest: 'sass/'
}
}
});
grunt.loadNpmTasks('grunt-sass-convert');
grunt.registerTask('default',['Sass']);
};

How to install Grunt plugin properly

Sorry, I'm newbie in npm-bower-grunt services. Maybe this question is stupid, but I can't find solution in google.
So, I have installed single page app based on npm/bower/grunt/angular.js
In the root I have gruntfile.js with this code
module.exports = function(grunt) {
var gtx = require('gruntfile-gtx').wrap(grunt);
gtx.loadAuto();
var gruntConfig = require('./grunt');
gruntConfig.package = require('./package.json');
gtx.config(gruntConfig);
// We need our bower components in order to develop
gtx.alias('build:standardversion', [
'compass:standardversion',
...
]);
gtx.finalise();
};
Else I have file grunt/compass.js with:
module.exports = {
standardversion: {
options: {
config: 'STANDARD/master/config.rb'
}
}
};
Then in bower_components folder I have gruntfiles for each plugin with code something like:
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
...
},
uglify: {
...
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', [
'karma',
'uglify'
]);
};
So now I have to install css-flip plugin from here https://www.npmjs.com/package/grunt-css-flip
I installed it with npm and now I don't know where to write a task for this.
Am I need to create new file in bower_components or somewhere else?
Please tell me or give me a link to understand it properly
Thanx

GruntFile returns [object, Object]

I am using a foundation/jekyll boilerplate.
Whenever I run grunt, it only returns the following in my style.css
[object Object]
It should have processed the scss from the foundation files.
Here is the gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
includePaths: ['bower_components/foundation/scss']
},
dist: {
options: {
outputStyle: 'compressed'
},
files: {
'css/style.css': 'scss/style.scss'
}
}
},
watch: {
grunt: { files: ['Gruntfile.js'] },
sass: {
files: 'scss/**/*.scss',
tasks: ['sass']
}
}
});
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('build', ['sass']);
grunt.registerTask('default', ['build','watch']);
}
The only thing I had to do was npm install node-sass.
I ran grunt and the only code in my style.css was [object, Object]
edit: ran npm install grunt-sass,
css now compiles nicely.
It seems that there's an error with recent version of node-sass where in error situations node-sass pipes [object Object] instead of failing and showing a proper stacktrace.
Your Gruntfile worked fine for me in a reduced test case, so validate your scss files before running the task.
Also, update to the newest node-sass/grunt-sass with npm install node-sass -save-dev, as it doesn't seem to behave that way (but throws the proper error instead).

How to use grunt-forever and grunt-watch together

I have both files: app.js which starts the http server, and main.js which is compiled by browserify and used in html as
So I have a Grunt configured with forever, browserify and watch.
I want that on app.js chance, the http must be restarted (via forever:restart), and when main.js changes, the build must be browserified (via browserify)
so, when i run grunt, says forever:start does not exist, any help ?
$ grunt
Warning: Task "forever:server1:start" not found. Use --force to continue.
this is my gruntfile:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify: {
dist: {
files: {
'examples/public/js/module.js': ['examples/main.js']
}
}
},
forever: {
server1: {
options: {
index: 'examples/app.js',
logDir: 'examples/logs'
}
}
},
watch: {
app: {
files: ['examples/*.js', 'examples/templates/*' ],
tasks: ['forever:server1:start']
},
web: {
files: ['examples/*.js', 'examples/templates/*' ],
tasks: ['browserify']
},
}
});
//grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-watch');
// Default task(s).
grunt.registerTask('default', ['browserify', 'forever:server1:start']);
grunt.registerTask('restart', ['browserify', 'forever:server1:restart']);
};
The task isn't found because you're missing grunt.loadNpmTasks('grunt-forever'). You might also find more success using something like nodemon instead of grunt.

Task 'min' not found

I've just set up Grunt for my project and I'm trying to run min task but I get the error:
Task 'min' not found
Here is my gruntfile.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
min: {
dist: {
src: "calculator/add.js",
dest: "add.min.js"
}
}
});
};
What could be wrong here? Thanks!
You need to load the npm module containing the task in to grunt. Update your Gruntfile so it looks like the example below.
Please note, that you need to have the correct name for the npm module to be loaded in. Although the grunt task may be called min, this is probably not the case for the npm module. I referenced grunt-example-min in the example file below, so be sure to update this to the correct name.
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
min: {
dist: {
src: "calculator/add.js",
dest: "add.min.js"
}
}
});
grunt.loadNpmTasks('grunt-example-min');
grunt.registerTask('default',['min']);
};

Resources