admin管理员组

文章数量:1426236

I have a webpack project wired with the jshint-loader which is defined like so:

postLoaders: [
       {
           test: /\.js$/,
           exclude: /node_modules/,
           loader: 'jshint-loader'
       }
],

and when I run webpack-dev-server I get the following warning in all of my files:

WARNING in ./js/main.js jshint results in errors Use the function form of "use strict". @ line 1 char 1 "use strict";

I tried using the "strict": false option in my config file under jshint but it did not help.

Adding 'use strict' in the files also did not help.

The only solution that I found was adding /*jshint globalstrict: true*/ in each js file in my project...

Does someone have a solution for it in the global scope?

Thanks.

I have a webpack project wired with the jshint-loader which is defined like so:

postLoaders: [
       {
           test: /\.js$/,
           exclude: /node_modules/,
           loader: 'jshint-loader'
       }
],

and when I run webpack-dev-server I get the following warning in all of my files:

WARNING in ./js/main.js jshint results in errors Use the function form of "use strict". @ line 1 char 1 "use strict";

I tried using the "strict": false option in my config file under jshint but it did not help.

Adding 'use strict' in the files also did not help.

The only solution that I found was adding /*jshint globalstrict: true*/ in each js file in my project...

Does someone have a solution for it in the global scope?

Thanks.

Share Improve this question asked Mar 11, 2015 at 14:25 Yoni DabushYoni Dabush 2204 silver badges13 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 2

You can create a file called .jshintrc that defines the global settings that you want jshint to use.

This shows all the possible settings for a file https://github./jshint/jshint/blob/master/examples/.jshintrc

You would simply create a .jshintrc and set globalstrict: true in that instead of in every js file.

The config section of jshint here: http://jshint./docs/ has more info if you need it.

turns out it is not that simple.

I found a great solution using eslint instead. Here is the example project: https://github./kriasoft/react-starter-kit/

I resolve this problem just adding the globalstrict: true like @AR7.

the next problem was fixed: https://github./webpack/jshint-loader/issues/13

About your problem in the ment you can do something like this:

I decided to put the jshint config in the package.json, another way to setup JSHint, so that way it's easier to read the config but if you want just create a new configuration there like jshint: { ... } or read from the .jshint file and convert it to json.

The problem is Webpack need to knows the JSHint configuration check here how they setup the jshint-loader

var path = require('path');
var pkg = require(path.resolve(__dirname, './package.json'));

....

module: {
  preLoaders: [{
    test: /\.js$/,
    loaders: [
      'jshint'
    ],
    include: [
      path.resolve(__dirname, 'src')
    ]
  }]
},
jshint: pkg['jshintConfig'] // This is the actually fix

you must setting hint to jshint that you use "use strict"; global into your files, you can use jshint options into webpack configuration file.

webpack.config.js file will be:

module.exports = {
    //...
    module: {
      //...
      postLoaders: [
       {
           test: /\.js$/,
           exclude: /node_modules/,
           loader: 'jshint-loader'
       }
      ] 
    },
    jshint: {
       strict: "global" // <-- adding strict mode option as global
    }
};

本文标签: javascriptHow to get rid of usestrict warning when using webpack and jshintloaderStack Overflow