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

别说谁变了你拦得住时间么 提交于 2019-12-08 03:40:05

问题


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

回答1:


Try installing the module manually.

npm install jshint-stylish

worked for me.




回答2:


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



回答3:


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

export NODE_PATH=./node_modules



来源:https://stackoverflow.com/questions/24143154/error-local-npm-module-jshint-stylish-not-found-when-it-exists-locally-via-sy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!