Grunt doesn't give any output [Ubuntu] - gruntjs

My grunt doesn't give any output, and I just installed all the system, NPM and grunt-cli. When I type "grunt -v" nothing is returned.
This is my package.json:
{
"name": "project",
"version": "2.0.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-coffee": "~0.7.0",
"grunt-contrib-compass": "~0.6.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-yui-compressor": "~0.3.0",
"grunt-contrib-cssmin": "~0.7.0"
}
}
And my Gruntfile.coffee is:
module.exports = (grunt) ->
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON("package.json")
coffee:
glob_to_multiple:
expand: true
flatten: true
src: ['assets/javascripts/source/*.coffee']
dest: 'assets/javascripts/build/'
ext: '.js'
compass:
dev:
options:
config: 'config.rb'
cssmin:
add_banner:
options:
banner: '/* Compilado em ' + grunt.template.today('dd/mm/yyyy') + ' */'
files:
'assets/styles/build/site.min.css': ['assets/styles/build/site.css']
'assets/styles/build/site-ie7.min.css': ['assets/styles/build/site-ie7.css']
uglify:
dev:
files:
'assets/javascripts/build/scripts.min.js':[
'assets/javascripts/build/scripts.js'
'assets/javascripts/build/zt-validator.js'
'assets/javascripts/build/jquery-zt.js'
]
dist:
files:
'assets/javascripts/build/scripts-full.min.js':[
'assets/javascripts/build/scripts.js'
'assets/javascripts/build/zt-validator.js'
'assets/javascripts/build/jquery-zt.js'
'assets/javascripts/build/site.js'
]
watch:
options: { spawn: false }
coffee:
files: ["assets/javascripts/source/*.coffee"]
tasks: ["coffee","uglify"]
compass:
files: ["assets/styles/**/*.sass","assets/styles/**/*.scss"]
tasks: ["compass","cssmin"]
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-compass"
grunt.loadNpmTasks "grunt-contrib-cssmin"
grunt.loadNpmTasks "grunt-contrib-uglify"
# Default task(s).
grunt.registerTask "default", ["coffee", "compass"]
I don't know how to debug it.

Try removing the package "node". It's not related to NodeJS and removing it resolved the problem for me.
You can accomplish this by running sudo apt-get remove node and reinstall nodejs-legacy with sudo apt-get install nodejs-legacy

I had to install 'node-legacy' on Ubuntu 13.10 in order to get 'grunt' working. Just installing 'node' was not enough.

If you aren't on the latest version of grunt-cli, upgrade it.
You might be getting caught by the problem this update fixed and that likely explains the different results you and I are getting with the switches.

Related

Grunt watch failing to reload config file - errors on change

The environment is: Linux 2.6.32-573.12.1.el6.x86_64 x86_64, via SSH
I have a slightly non-standard setup for my grunt, as detailed below:
/home/scoots/public_html/
grunt/
package.json
node_modules/
project1/
Gruntfile.js
project2/
Gruntfile.js
project1/
project2/
When I start grunt watch and make a change to my Gruntfile.js (Which is not a common occurance, but still something that might happen depending on the needs of the project), I get the following error:
$ cd ~/public_html/grunt/project1
$ grunt watch
Running "watch" task
Waiting...
Reloading watch config...
Fatal error: EACCES: permission denied, scandir '/home'
It's simple enough to deal with (just cancel and restart grunt) - but that requires me to notice. I can sometimes try and carry on working, but grunt watch will now be locked-up.
Also, what's annoying is this code used to work when I had grunt installed on my local (Windows) machine and ran it from a Node.js command prompt.
For reference, here is an example Gruntfile.js that exhibits this problem:
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('jit-grunt')(grunt);
grunt.file.setBase('../');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
site_dir: {
site: '../tcl/wp-content/themes/twentysixteen-child',
jscache: 'wp-content/themes/twentysixteen-child/js/src',
grunt: 'tcl'
},
watch: {
css: {
files: ['<%= site_dir.site %>/css/sass/*.scss'],
tasks: ['sass', 'postcss'],
options: {
spawn: false
}
},
scripts: {
files: ['<%= site_dir.site %>/js/src/*.js'],
tasks: ['include_file', 'uglify'],
options: {
spawn: false
}
},
configFiles: {
files: ['<%= site_dir.grunt %>/Gruntfile.js'],
options: {
reload: true
}
}
},
sass: {
options: {
style: 'expanded', // compressed in postcss
sourcemap: true,
sourceMapEmbed: true,
precision: 8,
includePaths: ['node_modules/bootstrap-sass/assets/stylesheets']
},
dist: {
files: {
'<%= site_dir.grunt %>/css/layout.css': '<%= site_dir.site %>/css/sass/layout.scss'
}
}
},
postcss: {
options: {
map: {
inline: false,
annotation: '<%= site_dir.grunt %>/css/maps/'
},
processors: [
require('autoprefixer')({
browsers: [
"Android 2.3",
"Android >= 4",
"Chrome >= 20",
"Firefox >= 24",
"Explorer >= 8",
"iOS >= 6",
"Opera >= 12",
"Safari >= 6"
]
}),
require('csswring')()
]
},
dist: {
src: '<%= site_dir.grunt %>/css/layout.css',
dest: '<%= site_dir.site %>/css/layout.min.css'
}
},
include_file: {
js: {
cwd: '<%= site_dir.grunt %>/',
src: [
'../<%= site_dir.site %>/js/src/common.js'
],
dest: '<%= site_dir.grunt %>/js/'
}
},
uglify: {
options: {
compress: {
warnings: true
},
mangle: true,
preserveComments: /(?:^!|#(?:license|preserve|cc_on))/
},
build: {
src: [
'<%= site_dir.grunt %>/<%= site_dir.jscache %>/common.js'
],
dest: '<%= site_dir.site %>/js/common.min.js'
}
}
});
grunt.registerTask('default', ['sass', 'postcss', 'include_file', 'uglify']);
};
And package.json:
{
"name": "Test",
"version": "0.1.0",
"dependencies": {
"bootstrap-sass": "3.3.7"
},
"devDependencies": {
"autoprefixer": "^6.4.1",
"csswring": "^5.1.0",
"grunt": "^1.0.1",
"grunt-contrib-uglify": "^2.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-include-file": "^0.1.3",
"grunt-postcss": "^0.8.0",
"grunt-sass": "^2.0.0",
"jit-grunt": "^0.10.0",
"time-grunt": "^1.4.0"
}
}
EDIT: Verbose / debug enabled:
$ grunt -v -d watch
Initializing
Command-line options: --verbose, --debug=1
Reading "Gruntfile.js" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK
Loading "Gruntfile.js" tasks...OK
+ default
Running tasks: watch
Loading "grunt-contrib-watch" plugin
Registering "/home/scoots/public_html/grunt/node_modules/grunt-contrib-watch/tasks" tasks.
Loading "watch.js" tasks...OK
+ watch
Running "watch" task
[D] Task source: /home/scoots/public_html/grunt/node_modules/grunt-contrib-watch/tasks/watch.js
Waiting...
Verifying property watch exists in config...OK
Verifying property watch.css.files exists in config...OK
Verifying property watch.scripts.files exists in config...OK
Verifying property watch.config.files exists in config...OK
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/__bookings.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/__variables.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_bootstrap-custom.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_contactform7.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_lightslider.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_lity.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/_zoom.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/css/sass/layout.scss for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/bootstrap.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/common.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/instafeed.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/lightslider.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/lity.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/scrollreveal.min.js for changes.
Watching ../tcl/wp-content/themes/twentysixteen-child/js/src/zoom.js for changes.
Watching tcl/Gruntfile.js for changes.
Watching tcl/css for changes.
Watching tcl/js for changes.
Watching tcl/wp-content for changes.
Clearing require cache for "tcl/Gruntfile.js" file...OK
[[[[I edit the Gruntfile here]]]]
Reloading watch config...
Fatal error: EACCES: permission denied, scandir '/home'
A leading slash in a files glob sometimes cause this error but grunt will not throw any errors. Just a silent fail with this warning.
make sure that your "files" config does not lead to this , and this <%= site_dir.site %> template does not lead to null or empty.
watch: {
css: {
files: ['<%= site_dir.site %>/css/sass/*.scss'],
tasks: ['sass', 'postcss'],
options: {
spawn: false
}
},
scripts: {
files: ['<%= site_dir.site %>/js/src/*.js'],
tasks: ['include_file', 'uglify'],
options: {
spawn: false
}
},
configFiles: {
files: ['<%= site_dir.grunt %>/Gruntfile.js'],
options: {
reload: true
}
}
}

grunt watch is not replacing sass file.please suggest me what i am doing wrong here

I am trying to watch sass changes but I am not be able to see any changes on main.css whenever I update on sass files.Can some please suggest me what I am doing wrong here I am new to grunt js .
{
"name": "test-scss",
"version": "0.1.0",
"devDependencies": {
"bootstrap-sass": "^3.3.7",
"grunt": "^1.0.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-sass": "^1.0.0",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "^1.0.0"
},
"scripts": {
"build-css": "node-sass --include-path scss sass/style.scss css/main.css"
}
}
/// here is my gruntjs file configuration
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
options: {
livereload: true
},
sass: {
files: ['**/*.scss'],
task: ['sass']
},
html: {
files: ['*.html']
}
},
sass: {
dist: {
files: {
'css/main.css': 'sass/style.scss'
}
}
},
connect: {
sever: {
options: {
keepalive: true,
hostname: 'localhost',
port: 3003,
base: '.',
open: true,
watch: true,
livereload: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.registerTask('default', ['sass', 'watch', 'connect']);
};
Grunt watch is a blocking task so grunt connect is never reached.
grunt-contrib-connect blocks only if keepalive: true is set otherwise it runs as long as grunt is running. As grunt watch runs indefinitely you do not need to force grunt-contrib-connect to "keepalive"
To fix.
keepalive: false //turn off keepalive
Move watch blocking task to execute last
grunt.registerTask('default', ['sass','connect','watch']);
If you absolutely need to run two blocking tasks together you can use a plugin like grunt-concurrent
https://stackoverflow.com/a/42319772/3656963
Or call each task separately using 2 command lines.
Also fix typo: task: ['sass'] to tasks: ['sass']

Running "responsive_images:dev" (responsive_images) task >> Unable to compile; no valid source files were found

I am trying to set grunt, I have already download GraphickMagick and ImageMAgick.
My OS is LINUX MINT.
When I try to run $grunt I get the following error:
Running "responsive_images:dev" (responsive_images) task
Unable to compile; no valid source files were found.
Unable to compile; no valid source files were found.
My current directory is /project-server:
project-server/images/
project-server/img/
project-server/node_modules/
project-server/Gruntfile.js
project-server/package.json
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
responsive_images: {
dev: {
options: {
engine: 'im',
sizes: [{
name: 'small',
width: '30%',
suffix: '_small',
quality: 20
},{
name: 'large',
width: '50%',
suffix: '_large',
quality: 40
}]
},
files: [{
expand: true,
src: ['*.{gif,jpg,png}'],
cwd: 'images/',
dest: 'images/'
}]
}
},
});
grunt.loadNpmTasks('grunt-responsive-images');
grunt.registerTask('default', ['responsive_images']);
};
package.json
{
"name": "project-server",
"version": "0.1.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-responsive-images": "^1.10.1"
}}
So,
src: ['*.{gif,jpg,png}'],
cwd: 'images/',
dest: 'images/'
Attention to cwd value, it says that my current directory is /images, so whenever he tries to find the value for src, it will search under /images. BUT my files {.png,.jpeg} arent under /images.
Then, all I had to do was to comment the cwd value. And it worked fine!

grunt-contrib-compass not work in npm

i had installed npm and grunt and then installed grunt-contrib-compass.
but when i run grunt. i have this error
Running “compass:dist” (compass) task
Warning: not found: compass Use –force to continue.
Aborted due to warnings
and this my gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compass: {
dist: {
options: {
sassDir: 'sass',
cssDir: 'css'
}
}
},
watch: {
css: {
files: '**/*.scss',
tasks: ['compass']
}
}
});
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default',['watch']);
}
You need to install the Compass Ruby gem, as detailed here. Basically you need to have installed Ruby, and then using that you can install the Compass gem and grunt-contrib-compass should work

Grunt-brunch server Fatal error: spawn ENOENT

I have an error executing "grunt server" :
Running "brunch:server" (brunch) task result in Fatal error: spawn ENOENT
Here you can find my dependencies from package.json :
"dependencies": {
"javascript-brunch": "1.7.0",
"coffee-script-brunch": "1.7.2",
"css-brunch": "1.7.0",
"stylus-brunch": "1.7.0",
"handlebars-brunch": "1.7.2",
"uglify-js-brunch": "1.7.3",
"clean-css-brunch": "1.7.1",
"jsenv-brunch": "1.4.2",
"auto-reload-brunch": "1.7.1",
"moment": "2.4.0",
"lodash": "2.4.0",
"grunt": "0.4.2",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-copy": "0.4.1",
"grunt-brunch": "0.0.2",
"grunt-shell": "0.6.1",
"grunt-contrib-htmlmin": "0.1.3",
"grunt-line-remover": "0.0.2"
},
"devDependencies": {},
"peerDependencies": {
"grunt": "0.4.2"
}
And here part of my gruntfile :
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
brunch: {
options: {
env: ['<%= company %>', '<%= platform %>'],
production: '<%= production %>'
},
build: {},
watch: {
options: {
watch: true
}
},
server: {
options: {
server: true
}
}
},
});
grunt.loadNpmTasks('grunt-brunch');
grunt.loadTasks('tasks');
grunt.registerTask('server', [
'init',
'clean:build',
'brunch:server'
]);
I tried many things nothing works, any ideas will be welcoming ?
The issue is due to the path settings in the task file: ./node_modules/grunt-brunch/tasks/brunch.coffee. As it is set now the brunch binary is not found leading to the ENOENT error. If you change the path to:
BASE = "#{__dirname}/../../../"
in line #2 of the task file, the binary is found and the plugin works.
EDIT: The issue only happens if there is a brunch installed locally on the base dir. In this case it seems brunch is NOT installed into the npm-modules of the grunt-brunch package (where the path is pointing to)
npm install --save brunch
The grunt-brunch plugin expects brunch to be a local dependency of your project. It is not set up to use a global brunch installation.

Resources