由于弹出后的lint警告,无法编译create-react-app

时间:2018-06-04 01:06:49

标签: reactjs webpack eslint create-react-app

我一直在关注React课程。下一步是使用npm run eject,以便可以使用css模块。

由于弹出我不能使用npm start。页面无法编译。出现一长串linting警告(实际上似乎来自webpack配置文件)。

我为这些文件和其他文件创建了一个.eslintignore文件:

./reactNotes.jsx
./nodeTest.js
./config
./scripts

但我的代码编辑器(vs代码)或webpack似乎都没有注意到这个文件。 eslint全局安装。

我还调查了eslint的webpack配置,其中包括exclude:

等选项
  {
    test: /\.(js|jsx|mjs)$/,
    enforce: 'pre',
    use: [
      {
        options: {
          formatter: eslintFormatter,
          eslintPath: require.resolve('eslint'),
        },
        loader: require.resolve('eslint-loader'),
      },
    ],
    include: paths.appSrc,
    exclude: /config/
  }

VS代码在我的用户设置中启用了eslint。

如何设置webpack(甚至可能是vs代码)来忽略目录和文件?

更新:这是.eslintrc:

{
    "parser": "babel-eslint",
    "extends": "react-app",
    "plugins": [
        "react",
        "jsx-a11y",
        "import"
    ],
    "rules": {
        "linebreak-style": [
            "error",
            "windows"
        ],
        "indent": [
            "error",
            4
        ],
        "react/prop-types": 0,
        "react/jsx-indent": 0,
        "jsx-a11y/click-events-have-key-events": 0,
        "jsx-a11y/no-noninteractive-element-interactions": 0,
        "max-len": 0,
        "arrow-body-style": 0,
        "react/jsx-indent-props": 0,
        "react/no-unescaped-entities": 0,
        "react/jsx-no-bind": 0,
        "arrow-parens": 0,
        "react/no-array-index-key": 0
    }
}

此外,npm安装并重新启动浏览器不起作用。

browser errors

3 个答案:

答案 0 :(得分:1)

在您的eslintigonre中,尝试更改

./config
./scripts

config/
scripts/

在ESLint的文档中,它是统计数据:

  

忽略模式的行为符合.gitignore规范

您可以找到完整的规范here

答案 1 :(得分:0)

loveky的回答修复了VS代码。

要将build属性添加到包含服务工作文件的webpack.config的exclude属性中,请执行以下操作:

  {
    test: /\.(js|jsx|mjs)$/,
    enforce: 'pre',
    use: [
      {
        options: {
          formatter: eslintFormatter,
          eslintPath: require.resolve('eslint'),
          emitError: false,
        },
        loader: require.resolve('eslint-loader'),
      },
    ],
    include: paths.appSrc,
    exclude: /(config|node_modules|registerServiceWorker.js|nodeTest.js|reactNotes.jsx|webpack.config)/,
  }

答案 2 :(得分:0)

Create-react-app在内部使用eslint进行linting,并且当该eslint检查引发错误时不运行,如果您已经分别配置了eslint(使用config .eslintrc.js),然后又将其弹出,则它开始使用该eslint您已配置的配置。我面临的问题是,在使用调试器时,它将无法启动并引发no-debugger规则的异常。因此,我创建了一个单独的eslint配置,并将其命名为test.eslintrc.js,在我的package.json中,我做到了: "lint": "eslint src -c test.eslintrc.js", "scripts"标签内

还可以使用.eslintignore并添加目录: 配置/ 脚本/ src / serviceWorker.js

相关问题