2

我的文件夹中有一个 linux 符号链接到一个名为 node_modules 的文件夹,其中包含 grunt 文件,但是当我运行 grunt 时,我得到了这个:

未找到本地 Npm 模块“jshint-stylish”。安装了吗?

我所有其他 npm 模块都工作正常,有什么想法吗?

我的咕噜声文件:

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');

权限:

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

..

编辑_______我作为记者在咕噜声中使用它:

  jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      all: [
4

3 回答 3

4

尝试手动安装模块。

npm install jshint-stylish

为我工作。

于 2015-12-10T21:04:02.650 回答
0

load-grunt-configs 所有者 creynders在这里建议错误
“找不到本地 Npm 模块'jshint-stylish'。它安装了吗?”
显然是由 jshint.js 配置文件中对 jshint-stylish 的要求引起的。
它找不到 jshint-stylish 模块,因为它位于项目外部的目录中。

但是我无法让他的建议对我有用,但我找到了自己的方式:

// 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 %>"]
        }
    }});
};
于 2016-11-07T18:43:59.967 回答
0

检查您的 NODE_PATH 环境变量是否引用了您的 node_modules 目录。
在本地它将是:

导出 NODE_PATH=./node_modules

于 2019-07-16T16:29:11.723 回答