Webpack 显示警告两次

Guy*_*yML 22 eslint webpack create-react-app typescript-eslint

我有一个被弹出的 CRA,并且最近将 Webpack 升级到版本 5,现在使用后npm run start我收到警告两次(附后),是否有任何选项可以只显示一次?我注意到在新的 CRA 项目中使用 ESLint webpack 插件时也会发生这种情况。

Compiled with warnings.

src/app/apollo/apollo.ts
  Line 15:7:   Unexpected console statement  no-console
  Line 18:21:  Unexpected console statement  no-console

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

WARNING in src/app/apollo/apollo.ts
  Line 15:7:   Unexpected console statement  no-console
  Line 18:21:  Unexpected console statement  no-console

webpack compiled with 1 warning
No issues found.
Run Code Online (Sandbox Code Playgroud)

小智 -1

我没有遇到只显示一次警告,而只是禁用的方法。
要禁用警告,您可以参考以下帖子

当您在控制台对象上使用方法(例如 console.log())时,会显示 ESLint 错误“eslint(无控制台)意外的控制台语句”。

要解决此问题,请在 .eslintrc.js 文件中将无控制台规则设置为关闭以禁用该规则。

  • .eslintrc.js如果您还没有文件,请创建一个文件。
  • 该文件应位于项目的根目录中,紧邻您的package.json文件。
  • 将以下规则添加到文件rules中的对象.eslintrc.js以禁用该no-console规则。

module.exports = {
    rules: {
        'no-console': 'off',
    },
};
Run Code Online (Sandbox Code Playgroud)