webpack3 jshint-loader does not work

Zorin picture Zorin · Jul 24, 2017 · Viewed 81.4k times · Source

I'm trying to follow this instruction https://webpack.js.org/loaders/jshint-loader/ and get an error:

My config file:

error text:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration has an unknown property 'jshint'. These properties are valid: object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, prof ile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? } For typos: please correct them. For loader options: webpack 2 no longer allows custom properties in configuration.

Answer

Tom Van Rompaey picture Tom Van Rompaey · Jul 24, 2017

The instructions on their website seem to be outdated as this isn't working indeed. There's an open issue about this on Github.

This configuration should work:

const path = require('path');

module.exports = {
  entry: {
    app: './index.js'
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
  },

  module: {
    rules: [{
      test: /\.js$/, // include .js files
      enforce: "pre", // preload the jshint loader
      exclude: /node_modules/, // exclude any and all files in the node_modules folder
      use: [{
        loader: "jshint-loader",
        // more options in the optional jshint object
        options: {  // ⬅ formally jshint property
          camelcase: true,
          emitErrors: false,
          failOnHint: false
        }
      }]
    }]
  },
};