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

7k Views Asked by At

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: [
3

There are 3 best solutions below

0
On

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

export NODE_PATH=./node_modules

0
On

Try installing the module manually.

npm install jshint-stylish

worked for me.

0
On

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 %>"]
        }
    }});
};