The Be Sure Blog

Code Snippets | Problem Solving | Tips & Tricks

The Be Sure Blog banner

Suppress Next.js img tag warnings

posted on 16.2.2023 by Below Surface in "Next.js"

A project that I work on was started on Next.js 12 and recently converted to Next.js 13. The page is static and I use the neat static export feature of Next.js. That's because the web hosting provider does not support Node.js and with the exported HTML files we can enjoy the speed of React with the lovely SEO features that Next.js makes possible. Back to topic:

For some reason - and especially with static exported pages - I always have issues using the Next.js image components and more than often I decide to switch to the good old <img /> element. Next.js will then give a warning, that those images will not be optimized. Because I compress the website images beforehand, this is not important to me anyways. To suppress this warnings, just add this to your .eslintrc.json file:

"rules": {
  "@next/next/no-img-element": "off"
}

The whole file may look like this now:

{
  "extends": "next/core-web-vitals",
  "rules": {
    "@next/next/no-img-element": "off"
  }
}

Tags:

next.js
image
img
suppress warnings

Sources:

https://stackoverflow.com/questions/68203582/error-do-not-use-img-use-image-from-next-image-instead-next-js-using-ht

More posts of this category

Do a static export of a Next.js website

Doing a static export in Next.js is easy and working great on basic web hosting services

Next.js

Change the port of a Next.js app

How to manually set the port from 3000 to any other number

Next.js

Next.js 13 - how to set dynamic HTML head titles

How to take a slug string and turn it into a HTML title tag

Next.js

Add a robots.txt to your Next.js website

How to add your robots.txt file

Next.js

Add Tailwind CSS to your Next.js app

A few commands and some possible error fixing and you are good to go!

Next.js

Next.js 13 Tailwind CSS hot-reload issue fix

With the currently experimental app directory, hot-reload does not work properly

Next.js

How to clear the cache of a Next.js application

How to create a fresh build without any cached data

Next.js

How i finally fixed "sh: 1: next: not found"

My release pipeline failed constantly and it took me three hours to figure out the issue

Next.js

How I fixed "Parsing error: DeprecationError"

'originalKeywordKind' has been deprecated since v5.0.0 (...)

Next.js