不能在webpack中使用eslint加载器

时间:2017-03-27 10:00:56

标签: javascript webpack eslint

我对webpack越来越熟悉了。在我尝试将eslint加载器添加到我的webpack配置之前,它进展顺利。我得到了

   ./src/index.js中的错误   模块构建失败:错误:找不到模块'eslint'

运行webpack命令时在我的控制台中

。这是我的webpack.config.js

let path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname + '/dist'),
    filename: 'bundle.js',
  },
  module: {
    rules: [{
      test: /\.js$/,
      use: [
        'eslint-loader', {
        loader: 'babel-loader',
        query: {
          presets: ['es2015']
        }
      }],
      exclude: /node_modules/,
    }, {
      test: /\.scss$/,
      use: [{
          loader: 'style-loader' // creates style nodes from JS strings
      }, {
          loader: 'css-loader' // translates CSS into CommonJS
      }, {
          loader: 'sass-loader' // compiles Sass to CSS
      }],
      exclude: /node_modules/
    }]
  }
}

我的package.json:

{
  "name": "animatio",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server",
    "deploy": "git push evennode master"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.24.0",
    "babel-loader": "^6.4.1",
    "babel-preset-es2015": "^6.24.0",
    "css-loader": "^0.27.3",
    "eslint-loader": "^1.7.0",
    "express": "^4.15.2",
    "sass-loader": "^6.0.3",
    "style-loader": "^0.16.0",
    "webpack": "^2.3.2"
  },
  "dependencies": {
    "node-sass": "^4.5.1",
    "webpack": "^2.3.2"
  }
}

最后我的src / index.js:

import styles from './main.scss';

console.log('Something.')

提前谢谢。

2 个答案:

答案 0 :(得分:1)

答案非常明显。 我没有安装eslint本身(仅限加载器)。安装和.eslint文件创建后,它可以正常工作。

答案 1 :(得分:0)