Error Local Npm module "jshint-stylish" not found when it exists locally (via symlink) - jshint

I have a linux symlink to a folder called node_modules in my folder with the grunt file but when I run grunt I get this:
Local Npm module "jshint-stylish" not found. Is it installed?
All my other npm modules work fine,any ideas?
my grunt file:
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-closure-compiler');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('jshint-stylish');
permissions:
me#pc:~/dev/root/node_modules$ ls -l
total 96
..
drwxr-xr-x 3 me me 4096 Jun 10 14:57 grunt-shell
drwxr-xr-x 3 me me 4096 Jun 10 15:00 jshint-stylish
..
EDIT_____________________
I'm using it in grunt as a reporter:
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: [

Try installing the module manually.
npm install jshint-stylish
worked for me.

The load-grunt-configs owner creynders suggests here that the error
"Local Npm module 'jshint-stylish' not found. Is it installed?"
is apparently caused by the requiring of jshint-stylish in the jshint.js config file.
It can't find the jshint-stylish module since it's in a directory outside the project.
However I was unable to make his suggestion working for me, but I found my own way:
// gruntfile.js
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
config: grunt.file.readJSON('grunt-config.json'),
jshint_reporter: require('jshint-stylish')
});
// grunt-config.json
{
"jsHintFiles" : [
"**/modules/*.js"
]
}
// jshint.js
module.exports = function(grunt) {
"use strict";
grunt.config.merge({"jshint": {
"default": {
options: {
reporter: "<%= jshint_reporter %>"
},
src: ["<%= config.jsHintFiles %>"]
}
}});
};

Check that your NODE_PATH environment variable references your node_modules directory.
Locally it will be:
export NODE_PATH=./node_modules

Related

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

use grunt to update package dependancy version numbers

I have two projects EasyUI and EasyUI-Layout. EasyUI-Layout depends on EasyUI. I have grunt files set up to build them and push them to github. Here are the abridged grunt files:
// easyui
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify:...,
bumpup: {
file: 'package.json'
},
shell: {
git: ...
},
watch: ...
});
grunt.registerTask('g', ['bumpup', 'browserify', 'shell:git']);
};
// easyui-layout
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
browserify:...,
bumpup: {
file: 'package.json'
},
shell: {
git: ...,
npm: ...
},
watch: ..
});
grunt.registerTask('g', ['shell:npm', 'bumpup', 'browserify', 'shell:git']);
};
What I would like is that when I build and commit the EasyUI-Layout project, its package json is updated with the latest version number from EasyUI. At the moment, for example, the version number for EasyUI dependency in the package.json stays stuck on 0.0.0. Here is the abridged package.json file:
{
"name": "easyui-layout",
"version": "0.0.3",
"dependencies": {
"easyui": "0.0.0"
}
}
Say the EasyUI version number is 0.0.7, then the next time I build EasyUI-Layout with grunt I would like the package.json to be:
{
"name": "easyui-layout",
"version": "0.0.4",
"dependencies": {
"easyui": "0.0.7"
}
}
I assume this is possible with bump or bumpup? But a little experimentation has gotten me nowhere.
No, these types of things should be manually specified. You can use semver ranges though to have the package automatically install
Let me answer my own question. Since I'm publishing EasyUI to npmjs.org let's assume the latest version is up there. Here's the abridged grunt file for the EasyUI-Layout package:
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
shell: {
npm: {
command: [
'npm install easyui#latest --save'
].join('&&')
}
}
});
This just forces npm to install the latest version of EasyUI and updates the package.json file.
Simple as that. No need for other grunt tasks, custom or otherwise, and nothing to do with semver.

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.

grunt browser sync not injecting changes

I'm trying to get grunt-browser-sync to inject any css changes into an open browser when a file is updated/changed. But for some reason, I can seem to get it to work and grunt is not giving me any errors to let me know it's not working.
I'm currently using MAMP since it's a Wordpress based project.
Here's my Gruntfile.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
build: {
src: '_/js/libs/*.js', //input
dest: '_/js/functions.min.js' //output
}
},
sass: {
dist: {
options: {
loadPath: require('node-bourbon').includePaths,
loadPath: require('node-neat').includePaths,
style: 'compressed'
},
files: {
'style.css': 'scss/style.scss'
}
}
},
autoprefixer: {
dist: {
files: {
'style.css': 'style.css'
}
}
},
browserSync: {
dev: {
bsFiles: {
src : 'style.css'
},
options: {
watchTask: true
}
}
},
watch: {
options: {
livereload: true
},
js: {
files: ["_/js/libs/*.js"],
tasks: ["ugilify"],
},
sass: {
files: ["scss/*.scss"],
tasks: ["sass", "autoprefixer", "browserSync"],
},
php: {
files: ['*.php']
},
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-browser-sync');
// Default task(s).
grunt.registerTask('default', ['uglify', 'sass', 'browserSync', 'watch', 'autoprefixer']);
};
and here's the output when I save/update a file:
Running "watch" task
Waiting...
>> File "scss/global.scss" changed.
Running "sass:dist" (sass) task
File style.css created.
Running "autoprefixer:dist" (autoprefixer) task
File style.css created.
Running "browserSync:dev" (browserSync) task
Done, without errors.
Completed in 1.478s at Wed May 07 2014 18:47:40 GMT-0500 (CDT) - Waiting...
But then I have to physically refresh the browser to see the changes.
I'm not sure if I am missing something within the grunt file or what.
The only version of grunt-browser-sync that works for me with this code is 1.9.1. So, un-install your current version and
npm install grunt-browser-sync#1.9.1 --save-dev
I encountered the same issue and have opened an issue here
Github grunt-browser-sync repo with issues 58

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.

Resources