Reactjs 由于弹出后出现lint警告,无法编译create react应用程序
我一直在学习反应课程。下一步是使用Reactjs 由于弹出后出现lint警告,无法编译create react应用程序,reactjs,webpack,eslint,create-react-app,Reactjs,Webpack,Eslint,Create React App,我一直在学习反应课程。下一步是使用npm run eject,以便可以使用css模块 由于弹出,我无法使用npm启动。该页无法编译。出现了一长串的linting警告(实际上似乎来自Web包配置文件) 我已为这些文件和其他文件创建了一个.eslintignore文件: ./reactNotes.jsx ./nodeTest.js ./config ./scripts 但我的代码编辑器(vs代码)或网页似乎都没有注意到这个文件。eslint是全局安装的 我还研究了eslint的webpack配置,
npm run eject
,以便可以使用css模块
由于弹出,我无法使用npm启动。该页无法编译。出现了一长串的linting警告(实际上似乎来自Web包配置文件)
我已为这些文件和其他文件创建了一个.eslintignore文件:
./reactNotes.jsx
./nodeTest.js
./config
./scripts
但我的代码编辑器(vs代码)或网页似乎都没有注意到这个文件。eslint是全局安装的
我还研究了eslint的webpack配置,包括以下选项:
{
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安装和重新启动浏览器也不起作用
在您的eslintigonre中,尝试更改
./config
./scripts
到
在ESLint的文档中,它统计:
忽略模式的行为符合.gitignore规范
您可以找到完整的规范loveky的答案修复了VS代码 要修复包含service worker文件的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应用程序在内部使用eslint进行筛选,并且在eslint检查引发错误时不会运行。如果您单独配置了eslint(使用config.eslintrc.js)并已弹出,则它将开始使用您配置的eslint配置。我面临的问题是,在使用调试器时,它不会启动并抛出
no debugger
规则的异常。因此,我创建了一个单独的eslint配置,并将其命名为test.eslintrc.js
,在我的package.json
中,我做到了:
“lint”:“eslint src-c test.eslintrc.js”,
内部“脚本”
标记
您还可以使用.eslintignore并添加目录:
配置/
剧本/
src/serviceWorker.js此外,您不需要单独的test.eslintrc.js文件,只需修改
eslintConfig
中的package.json
并在其中添加规则即可。
{
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)/,
}