create-react-project
创建了一个项目。问题是,在开发过程中,每当 ESLint 出现问题时,构建就会失败并且无法编译代码。
我能否在保持构建运行的同时仍然运行ESLint,并报告稍后修复的错误?
如果你想强制 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, HERE
},
}],
},
错误和警告
默认情况下,该加载器将自动调整错误报告,具体取决于eslint错误/警告计数。您仍然可以通过使用
emitError
或emitWarning
选项来强制执行此行为:
emitError
(默认值:false
)如果将此选项设置为 true,则加载器将始终返回错误。
emitWarning
(默认值:false
)如果设置了此选项,则加载器将始终返回警告。如果您正在使用热模块替换,则可能希望在开发中启用此选项,否则更新将在出现eslint错误时被跳过。
...
只需在您的.env
文件中添加DISABLE_ESLINT_PLUGIN=true
即可。
干杯!
DISABLE_ESLINT_PLUGIN=true npm run build
。 - VityaSchel'DISABLE_ESLINT_PLUGIN'
未被识别为内部或外部命令。 - Karma Blackshawnpm config set script-shell "C:\path\to\bash.exe"
可以告诉 npm 使用 bash 而不是 cmd。 - Annan Yearian由于eslint-loader
现已过时,create-react-app
中现在使用eslint-webpack-plugin
,请查看文档。我能通过向eslint-webpack-plugin
添加两个选项来解决类似的问题。
在弹出你的React应用程序后,请将这些选项添加到ESLintPlugin
选项中:
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'
})
}
}
})
如果您想在2021年解决这个问题,您可以在.env.development文件中设置以下内容以忽略TypeScript错误。
TSC_COMPILE_ON_ERROR=true
来源: https://create-react-app.dev/docs/advanced-configuration/#:~:text=TSC_COMPILE_ON_ERROR
另外,要忽略ESLint错误,请使用craco来覆盖eslint-webpack-plugin
的默认配置以在开发环境中忽略错误。
const eslintWebpackPlugin = require("eslint-webpack-plugin");
const process = require("process");
module.exports = {
webpack: {
configure: (config) => {
config.plugins.forEach((plugin) => {
if (plugin instanceof eslintWebpackPlugin) {
// Ignore ESLint Errors.
plugin.options.failOnError = process.env.NODE_ENV === "production";
}
});
return config;
},
},
};
可能我回答晚了,但如果在.env
文件中添加ESLINT_NO_DEV_ERRORS=true
,则错误就会得到解决。
P.S:它适用于react script 4.0.3
及以上版本。
好的,我刚刚从我的webpack配置文件中注释掉了这些行。
// {
// test: /\.(js|jsx|mjs)$/,
// enforce: 'pre',
// use: [
// {
// options: {
// formatter: eslintFormatter,
// eslintPath: require.resolve('eslint'),
//
// },
// loader: require.resolve('eslint-loader'),
// },
// ],
// include: paths.appSrc,
// },
webpack.config.js
是一个用于配置 webpack 的 JavaScript 文件。它包含了各种选项,可以控制 webpack 的行为和打包输出的结果。通过修改webpack.config.js
文件,开发者可以更好地管理项目依赖和构建过程。 - Danziger