Grunt警告:路径必须是字符串。收到空

时间:2016-06-14 09:30:37

标签: gruntjs jshint grunt-contrib-jshint

当我尝试使用Grunt编译时,我收到此错误。我之前没有使用它,但我似乎只是在这个项目中遇到这个错误,它适用于我服务器上的其他项目。

  

跑步" jshint:main" (jshint)任务   警告:路径必须是字符串。收到null使用--force继续。

     

因警告而中止。

Grunt文件

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    uglify: {

      options: {
        mangle: false
      },

      target: {
        files: {
          'script/dist/main.min.js': 'script/dist/main.js'
        }
      },

      build: {
        files: {
          'script/dist/build.min.js': 'script/dist/build.min.js'
        }
      }

    },

    concat: {
      options: {
        stripBanners: true,
        banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
          '<%= grunt.template.today("yyyy-mm-dd") %> */',
      },

      srcJS: {
        src: ['script/src/menu.js',
          'script/src/custom_plugins.js',
          'script/src/banner.js',
          'script/src/latestNews.js',
          'script/src/officers.js',
          'script/src/eventsCalendar.js',
          'script/src/combinedSocialMedia.js',
          'script/src/haveYourSay.js',
          'script/src/photoGallery.js',
          'script/src/countdown.js'
        ],
        dest: 'script/dist/main.js'
      },

      css: {
        src: ['style/libs/bootstrap.min.css',
          'style/libs/bootstrap-theme.min.css',
          'style/src/css/*'
        ],
        dest: 'style/dist/build.min.css'
      },

      build: {
        src: ['script/libs/jquery.easing.min.js',
          'script/dist/main.js',
          'script/libs/bootstrap.min.js',
          'script/libs/velocity.min.js',
          'script/libs/date.js',
          'script/libs/jquery.timeago.js',
          'script/libs/owl.carousel.min.js'
        ],
        dest: 'script/dist/build.min.js'
      }

    },

    jshint: {

      main: 'script/dist/main.js'

    },

    watch: {

      js: {
        files: 'script/src/*',
        tasks: ['concat:srcJS', 'uglify:target', 'jshint:main', 'copy:js']
      },

      css: {
        files: 'style/src/css/*',
        tasks: ['copy:css']
      },

      less: {
        files: 'style/src/less/*',
        tasks: ['less', 'copy:css']
      },

      html: {
        files: '*.html',
        tasks: ['validation', 'bootlint']
      }

    },

    clean: {
      js: [
        'script/dist/main.min.js',
        'dist/build.min.js',
        'dist/build.min.css'
      ]
    },

    copy: {
      css: {
        files: [

          {
            expand: true,
            'src': 'style/src/css/main.css',
            'dest': 'style/dist/',
            flatten: true,
            rename: function(dest, src) {
              return dest + src.replace('main', 'build.min');
            }
          },

          {
            expand: true,
            'src': 'style/dist/build.min.css',
            'dest': 'dist/',
            flatten: true
          },

        ]
      },

      js: {
        files: [{
          expand: true,
          'src': 'script/dist/build.min.js',
          'dest': 'dist/',
          flatten: true
        }]
      }
    },

    validation: {
      options: {
        reset: grunt.option('reset') || false,
        stoponerror: true,
        relaxerror: ['Bad value X-UA-Compatible for attribute http-equiv on element meta.'] //ignores these errors
      },
      files: {
        src: ['homepage.html']
      }
    },

    bootlint: {
      options: {
        stoponerror: false,
        relaxerror: ['E001', 'E003', 'E031', 'W001', 'W002', 'W003', 'W005', 'W007', 'W009', 'E013']
      },
      files: ['homepage.html'],
    },

    less: {
      build: {
        options: {
          paths: ["style/src/less"],
          cleancss: true,
          compress: true
        },
        files: {
          "style/src/css/main.css": "style/src/less/main.less"
        }
      }
    }

  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-html-validation');
  grunt.loadNpmTasks('grunt-bootlint');

  // Default task(s).
  //grunt.registerTask('default', ['concat:srcJS','concat:css','uglify','jshint:main']);
  grunt.registerTask('default', [
    'validation',
    'bootlint',
    'concat:srcJS',
    'jshint:main',
    'uglify:target',
    'clean',
    'concat:build',
    'uglify:build',
    'less',
    'copy'
  ]);
};

4 个答案:

答案 0 :(得分:15)

reporterOutput必须是字符串。省略时,将其视为null

在Gruntfile.js中为它提供一个空字符串

jshint: {
    main: 'script/dist/main.js',
    reporterOutput: '' // <-- Add an empty String here
}

答案 1 :(得分:3)

如果你正在使用任何发电机给这样的话

jshint: {
      main: {
        options: {
            jshintrc: '.jshintrc',
            reporterOutput: "" // Empty string inside options
        },
        src: createFolderGlobs('*.js')
      }
    }

答案 2 :(得分:1)

对我来说,它是在配置对象的reporterOutput中添加Gruntfile.js空字符串值,如:

{
  jshint: {
     options: {
        jshintrc: ".jshintrc",
        reporterOutput: ''
     }
  }
}

修复它。

答案 3 :(得分:0)

此错误与jshint库的版本有关。要解决此问题,请更改最新的

的当前jshint版本

$ npm install grunt-contrib-jshint@latest --save-dev

无论如何,将jshint文件中的package.json版本手动更改为1.1.0。不要忘记使用以下声明更新项目:

npm install