由于弹出后出现 lint 警告,无法编译 create-react-app
Failed to compile create-react-app due to lint warnings after ejecting
我一直在学习 React 课程。下一步一直在使用 npm run eject
以便可以使用 css 个模块。
弹出后我无法使用 npm start。该页面无法编译。出现一长串 linting 警告(实际上似乎来自 webpack 配置文件)。
我已经为这些文件和其他文件创建了一个 .eslintignore 文件:
./reactNotes.jsx
./nodeTest.js
./config
./scripts
但我的代码编辑器 (vs code) 或 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 Code 在我的用户设置中启用了 eslint。
如何设置 webpack(甚至可能是 vs code)来忽略目录和文件?
更新:这里是 .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 安装和重新启动浏览器也不起作用。
在你的 eslintignore 中,尝试更改
./config
./scripts
到
config/
scripts/
在 ESLint 文档中,它统计:
Ignore patterns behave according to the .gitignore specification
您可以找到完整的规范here
loveky 的回答修复了 VS 代码。
要修复构建,请添加一个排除 属性 到 webpack.config,其中包括服务工作者文件:
{
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)/,
}
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
我一直在学习 React 课程。下一步一直在使用 npm run eject
以便可以使用 css 个模块。
弹出后我无法使用 npm start。该页面无法编译。出现一长串 linting 警告(实际上似乎来自 webpack 配置文件)。
我已经为这些文件和其他文件创建了一个 .eslintignore 文件:
./reactNotes.jsx
./nodeTest.js
./config
./scripts
但我的代码编辑器 (vs code) 或 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 Code 在我的用户设置中启用了 eslint。
如何设置 webpack(甚至可能是 vs code)来忽略目录和文件?
更新:这里是 .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 安装和重新启动浏览器也不起作用。
在你的 eslintignore 中,尝试更改
./config
./scripts
到
config/
scripts/
在 ESLint 文档中,它统计:
Ignore patterns behave according to the .gitignore specification
您可以找到完整的规范here
loveky 的回答修复了 VS 代码。
要修复构建,请添加一个排除 属性 到 webpack.config,其中包括服务工作者文件:
{
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)/,
}
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