【问题标题】:ESLint looking for config in src file (configured in default way)ESLint 在 src 文件中寻找配置(默认配置)
【发布时间】:2019-08-03 03:20:48
【问题描述】:

我通过 NPM 安装了 eslint-loader 和 eslint loader 作为依赖项。按照在线指南,我把它放在我的 module.exports 中。奇怪的是,虽然经过研究我知道 eslint 会在没有提供默认配置文件的情况下查找默认配置文件,但我得到了以下构建错误。

./src/index.js 中的错误 模块构建失败(来自 ./node_modules/eslint-loader/index.js): 错误:在 C:\Users\lukea\Local Sites\molehills-to-mountains\app\public\wp-content\themes\auberge-child\src 中找不到 ESLint 配置。

这是我的 module.exports 中的 eslint 对象

    {
            test: /\.js$/,
            enforce: "pre",
            exclude: /node_modules/,
            loader: "eslint-loader",
    },

很有可能需要更多信息,但由于我的代码库很大,我会根据反馈提供信息。谢谢堆栈。

【问题讨论】:

    标签: javascript node.js webpack


    【解决方案1】:

    我正在使用这些版本

    "eslint": "^5.0.0",
    "eslint-loader": "2.0.0"
    

    在我的 .eslintrc 文件中

    {
      "parser": "babel-eslint",
      "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "ecmaFeatures": {
          "jsx": true,
          "modules": true,
          "experimentalObjectRestSpread": true
        }
      },
      "env": {
        "es6": true
      },
      "plugins": ["react"],
      "extends": ["eslint:recommended", "plugin:react/recommended"],
      "rules": {
        "comma-dangle": [2, "never"],
        "react/jsx-uses-vars": "error",
        "no-var": "error",
        "no-unused-vars": "warn",
        "no-console": "off",
        "no-debugger": "off",
        "no-unexpected-multiline": "warn",
        "no-alert": "off",
        "comma-spacing": [2, { "before": false, "after": true }]
      },
      "settings": {
        "react": {
          "pragma": "React",
          "version": "15.6.1"
        }
      },
      "globals": {
        "Promise": true,
        "alert": true,
        "global": true,
        "window": true,
        "document": true,
        "process": true,
        "module": true,
        "console": true,
        "sessionStorage": true,
        "localStorage": true
      }
    }
    

    然后是我的 webpack

    module: {
        rules: [{
                test: /\.scss$/,
                use: [
                    'style-loader',
                    MiniCssExtractPlugin.loader,
                    {
                        loader: "css-loader",
                        options: {
                            minimize: true,
                            sourceMap: true
                        }
                    },
                    {
                        loader: "sass-loader"
                    }
                ]
            },
            {
                test: /\.(js|jsx)$/,
                exclude: /node_modules/,
                loader: ["babel-loader", "eslint-loader"] // here
            },
            {
                test: /\.(jpe?g|png|gif)$/i,
                loader: "file-loader"
            },
            {
                test: /\.(woff|ttf|otf|eot|woff2|svg)$/i,
                loader: "file-loader"
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      • 2017-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      相关资源
      最近更新 更多