Reactjs 忽略或防止ESLint错误破坏React项目中的生成(创建React项目)
我最近用Reactjs 忽略或防止ESLint错误破坏React项目中的生成(创建React项目),reactjs,webpack,webpack-2,eslint,eslintrc,Reactjs,Webpack,Webpack 2,Eslint,Eslintrc,我最近用create-react-project创建了一个项目 问题是,在我开发的过程中,每当ESLint出现问题时,构建就会中断,并且不会编译代码 我可以在运行ESLint并报告稍后将修复的错误的同时保持构建运行吗?好的,我刚刚从我的网页配置中注释了这行内容 // { // test: /\.(js|jsx|mjs)$/, // enforce: 'pre', // use: [ // { // options: { //
create-react-project
创建了一个项目
问题是,在我开发的过程中,每当ESLint出现问题时,构建就会中断,并且不会编译代码
我可以在运行ESLint并报告稍后将修复的错误的同时保持构建运行吗?好的,我刚刚从我的网页配置中注释了这行内容
// {
// test: /\.(js|jsx|mjs)$/,
// enforce: 'pre',
// use: [
// {
// options: {
// formatter: eslintFormatter,
// eslintPath: require.resolve('eslint'),
//
// },
// loader: require.resolve('eslint-loader'),
// },
// ],
// include: paths.appSrc,
// },
如果要强制ESLint始终发出警告(不会停止生成)而不是错误,则需要设置
emitWarning:true
:
{
enforce: 'pre',
include: paths.appSrc,
test: /\.(js|jsx|mjs)$/,
use: [{
loader: require.resolve('eslint-loader'),
options: {
formatter: eslintFormatter,
eslintPath: require.resolve('eslint'),
emitWarning: true, since eslint-loader
is now deprecated and eslint-webpack-plugin
is now used in create-react-app
check the docs, I was able to solve a similar issue by adding two option to the eslint-webpack-plugin
after ejecting your react app, add these options to the ESLintPlugin
options:
new ESLintPlugin({
// Plugin options
extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
formatter: require.resolve('react-dev-utils/eslintFormatter'),
eslintPath: require.resolve('eslint'),
context: paths.appSrc,
failOnError: false, <== `This one`
emitWarning: true, <== `And this one`
// ESLint class options
cwd: paths.appPath,
resolvePluginsRelativeTo: __dirname,
baseConfig: {
extends: [require.resolve('eslint-config-react-app/base')],
rules: {
...(!hasJsxRuntime && {
'react/react-in-jsx-scope': 'error'
})
}
}
})
{
强制执行:“预”,
包括:path.appSrc,
测试:/\(js | jsx | mjs)$/,
使用:[{
loader:require.resolve('eslint-loader'),
选项:{
格式化程序:eslintFormatter,
eslintPath:require.resolve('eslint'),
emitWarning:true,由于eslint加载程序
现在已被弃用,并且eslint网页包插件
现在用于create react app
检查,我通过向eslint网页包插件添加两个选项
弹出react应用程序后,将以下选项添加到ESLintPlugin
选项中:
新的ESLint插件({
//插件选项
扩展名:['js','mjs','jsx','ts','tsx'],
格式化程序:require.resolve('react-dev-utils/eslintFormatter'),
eslintPath:require.resolve('eslint'),
上下文:path.appSrc,
failOnError:false,非常感谢!!!我能问一下要放在哪个文件中吗?如果我不想弹出怎么办?我尝试了一些解决方案,但没有解决问题。其中之一是将警告隐藏在代码中,而应用程序只会在终端中显示,但这不适合我,因为我希望错误和警告出现在e代码。