next-optimized-images icon indicating copy to clipboard operation
next-optimized-images copied to clipboard

images that copied into the static folder(/_next/static/media/*) are damaged

Open Sharklegs opened this issue 2 years ago • 9 comments

next verison: 11.1.2 next-optimized-images version: 2.6.2

images can be found in .next/static/media/ but can not preview or open, tips: it may damaged.
in server open the image in new tab, it is a white empty Square picture.
and the inlineImageLimit is 8192 by default right? but no matter how small the image is, and how big the file size I set , inline can not work, I always get copied to the static folder of next.

I change next to 10.1.3 then it perform well no such problem.

next.config.js:

const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');


module.exports = withPlugins(
  [optimizedImages],
  {
    reactStrictMode: true,
    webpack5: true,
  },
);

example: there is an icon: assest/icon-tips.png

.main {
  background: url(../assets/icon-tips.png);
}

result:

.main {
  background: url(/_next/static/media/icon-tips.3d63b16b9e687dbf38305a2737e8895a.png);
}

Sharklegs avatar Dec 23 '21 07:12 Sharklegs

Facing the same issue with Next 12.0.4

The files in the .next/static/media folder are structured like module files. e.g.

module.exports = "/_next/static/images/filename_generated_by_next_optimized_images"

harig074 avatar Dec 24 '21 10:12 harig074

same issue with Next 12.0.4

redlarva avatar Jan 19 '22 12:01 redlarva

Same with 12.0.7

AlfieGoat avatar Jan 27 '22 15:01 AlfieGoat

+1

soundobj avatar Feb 18 '22 11:02 soundobj

After some digging I was able to create a workaround for the issue: The file: /node_modules/next-optimized-images/lib/index.js @ line 43 Replace:

      // remove (unoptimized) builtin image processing introduced in next.js 9.2
      if (enrichedConfig.module.rules) {
        enrichedConfig.module.rules.forEach((rule) => {
          if (rule.oneOf) {
            rule.oneOf.forEach((subRule) => {
              if (
                subRule.issuer && !subRule.test && !subRule.include && subRule.exclude
                && subRule.use && subRule.use.options && subRule.use.options.name
              ) {
                if ((String(subRule.issuer.test) === '/\\.(css|scss|sass)$/' || String(subRule.issuer) === '/\\.(css|scss|sass)$/') && subRule.use.options.name.startsWith('static/media/')) {
                  subRule.exclude.push(/\.(jpg|jpeg|png|svg|webp|gif|ico)$/);
                }
              }
            });
          }
        });
      }

with

      // remove (unoptimized) builtin image processing introduced in next.js 9.2
      if (enrichedConfig.module.rules) {
        enrichedConfig.module.rules.forEach((rule) => {
          if (rule.oneOf) {
            rule.oneOf.forEach((subRule) => {
              if (
                subRule.issuer && !subRule.test && !subRule.include && subRule.exclude
                /* && subRule.use && subRule.use.options && subRule.use.options.name */
              ) {
                if ((String(subRule.issuer.test) === '/\\.(css|scss|sass)$/' || String(subRule.issuer) === '/\\.(css|scss|sass)$/')/*  && subRule.use.options.name.startsWith('static/media/') */) {
                  subRule.exclude.push(/\.(jpg|jpeg|png|svg|webp|gif|ico)$/);
                }
              }
            });
          }
        });
      }

SStoliarchuk avatar Feb 25 '22 12:02 SStoliarchuk

same problem in nextjs 12.1 :(

wodka avatar Feb 28 '22 23:02 wodka

@wodka For the time being @SStoliarchuk's fix worked for me, forked it on https://github.com/jorgev259/next-optimized-images

jorgev259 avatar Mar 12 '22 01:03 jorgev259

+1. Had to stop using for now.

akinnee avatar Jun 09 '22 17:06 akinnee

After some digging I was able to create a workaround for the issue: The file: /node_modules/next-optimized-images/lib/index.js @ line 43 Replace:

      // remove (unoptimized) builtin image processing introduced in next.js 9.2
      if (enrichedConfig.module.rules) {
        enrichedConfig.module.rules.forEach((rule) => {
          if (rule.oneOf) {
            rule.oneOf.forEach((subRule) => {
              if (
                subRule.issuer && !subRule.test && !subRule.include && subRule.exclude
                && subRule.use && subRule.use.options && subRule.use.options.name
              ) {
                if ((String(subRule.issuer.test) === '/\\.(css|scss|sass)$/' || String(subRule.issuer) === '/\\.(css|scss|sass)$/') && subRule.use.options.name.startsWith('static/media/')) {
                  subRule.exclude.push(/\.(jpg|jpeg|png|svg|webp|gif|ico)$/);
                }
              }
            });
          }
        });
      }

with

      // remove (unoptimized) builtin image processing introduced in next.js 9.2
      if (enrichedConfig.module.rules) {
        enrichedConfig.module.rules.forEach((rule) => {
          if (rule.oneOf) {
            rule.oneOf.forEach((subRule) => {
              if (
                subRule.issuer && !subRule.test && !subRule.include && subRule.exclude
                /* && subRule.use && subRule.use.options && subRule.use.options.name */
              ) {
                if ((String(subRule.issuer.test) === '/\\.(css|scss|sass)$/' || String(subRule.issuer) === '/\\.(css|scss|sass)$/')/*  && subRule.use.options.name.startsWith('static/media/') */) {
                  subRule.exclude.push(/\.(jpg|jpeg|png|svg|webp|gif|ico)$/);
                }
              }
            });
          }
        });
      }

it is works

beihai-shinan avatar Oct 11 '22 03:10 beihai-shinan