一、简介
-
在
Nextjs发开中没有使用自带的<Image />组件,而选择使用<img />标签,导致报警告:Using
<img>could result in slower LCP and higher bandwidth. Consider using<Image />fromnext/imageto automatically optimize images. This may incur additional usage or cost from your provider. See: nextjs.org/docs/messag… @next/next/no-img-element
二、解决方案
方式一
-
从
Next.js 11开始,Nextjs开箱即用的支持了ESLint,现在提供了一组新规则,包括@next/next/no-img-element规则。可以在
.eslintrc文件中禁用此特定ESLint规则,就像其他规则一样。.eslintrc.json
{ "extends": "next/core-web-vitals", "rules": { // 关闭 Next.js 针对 <Image> 的警告 "@next/next/no-img-element": "off" } }.eslintrc.js
module.exports = { extends: 'next/core-web-vitals', rules: { // 关闭 Next.js 针对 <Image> 的警告 '@next/next/no-img-element': 'off' } }
方式二
-
终极技能,在
next.config.js中直接关闭ESLint。module.exports = { eslint: { ignoreDuringBuilds: true, } }