react-optimized-image icon indicating copy to clipboard operation
react-optimized-image copied to clipboard

Err : Babel plugin 'react-optimized-image/plugin' not installed or this component could not be recognized by it.

Open vakhariaheet opened this issue 3 years ago • 26 comments

Screenshot 2020-11-28 at 1 55 01 AM

vakhariaheet avatar Nov 27 '20 20:11 vakhariaheet

I am also getting this error. I don't know why. @heet-vakharia have you found a solution yet?

ohansFavour avatar Dec 04 '20 18:12 ohansFavour

no bro

vakhariaheet avatar Dec 04 '20 19:12 vakhariaheet

@ohansFavour @heet-vakharia hey guys, did you found a solution?

media-maven avatar Jan 12 '21 12:01 media-maven

Nope

On Tue, 12 Jan, 2021, 6:28 pm media-maven, [email protected] wrote:

@ohansFavour https://github.com/ohansFavour @heet-vakharia https://github.com/heet-vakharia hey guys, did you found a solution?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cyrilwanner/react-optimized-image/issues/19#issuecomment-758638816, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMGALUKPQ6O3UJ6MWQL2PI3SZRBPRANCNFSM4UFI7H4A .

vakhariaheet avatar Jan 12 '21 13:01 vakhariaheet

Same issue

bensbits91 avatar Jan 17 '21 17:01 bensbits91

Same issue here

LukeWood avatar Jan 23 '21 20:01 LukeWood

Any fix?

coolbeatz71 avatar Jan 25 '21 03:01 coolbeatz71

I'm using v2 for now. I have it working with these plugins: imagemin-mozjpeg, imagemin-optipng, imagemin-svgo, responsive-loader, sharp and webp-loader.

bensbits91 avatar Jan 25 '21 12:01 bensbits91

Same for me - the lib does not work as expected at first install :( which is sad

t1gor avatar Feb 08 '21 11:02 t1gor

I'm using v2 for now. I have it working with these plugins: imagemin-mozjpeg, imagemin-optipng, imagemin-svgo, responsive-loader, sharp and webp-loader.

@bensbits91 could you please describe what's v2?

t1gor avatar Feb 08 '21 12:02 t1gor

@t1gor I'm actually using next-optimized-images with a next.js project: https://github.com/cyrilwanner/next-optimized-images. Version 3 has similar issues, so I reverted to version 2, which is working well. I'm not sure if there's a version 2 of react-optimized-image

bensbits91 avatar Feb 08 '21 14:02 bensbits91

Allright, thanks.

In case someone is still intrested, I managed to get it to work without the lib at all:

  1. Added customize-cra
  2. Add config-overrides.js
// config-overrides.js
const {override, addWebpackModuleRule} = require('customize-cra');

module.exports = override(
	addWebpackModuleRule({
		test: /\.(png|jpe?g|webp|tiff?)$/i,
		use: [
			'file-loader',
			{
				loader: 'webpack-image-resize-loader',
				options: {
					width: 1000,
				},
			},
		],
	}),
);
  1. In components code, use it's params in way:
import SomeImageFile from 'Assets/Images/some-image-file.png?width=305&height=337&quality=85';

where width, height & quality are the params of the webpack loader. Check the docs for options: https://github.com/Calvin-LL/webpack-image-resize-loader#options

Hope that helps someone.

t1gor avatar Feb 08 '21 14:02 t1gor

@cyrilwanner I have been able to diagnose at least one case in which this bug occurs.

If the require call is performed in a higher component then passed down to another component where the Img component is, the srcRaw attribute is not built. The require call must be sent directly to the Img.

This can be problematic if you want to create a component which receives an image to render as an argument, and performs several other functions besides rendering the <Img>.

An example:

export const ImageWithCaption = ({image, caption}) => {
    return (<>
      <Img type="captioned" src={image} />
      <span style={{color: 'gray'}}>{caption}</span>
    </>);
};

export const App = () => {
    return (<div>
      <ImageWithCaption caption="This is a bird." image={require('./images/bird.png')} />
    </div>);
};

Here, the Babel plugin (which searches specifically for <Img> components and reinterprets their src properties) is unable to apply the special data to the Img and the previously cited error occurs.

It is useful to know that this is the cause of the problem, but the result is that the component is highly restrictive in the places it can be used and reused.

EliteMasterEric avatar Feb 20 '21 08:02 EliteMasterEric

@MasterEric thanks for those details - I was just trying to add the v3 for the first time to my app and got that error. I have that exact case, where a component receives the image src as a prop. Hopefully this can be fixed 🤞

mryechkin avatar Apr 11 '21 23:04 mryechkin

Any status on this? This kinda defeats the purpose for a lot of its uses IMO. Thanks for all your hard work!

jrhager84 avatar May 11 '21 23:05 jrhager84

I also need this fixed, I need to dynamically render Img with sources get from MDX but no matter what I try I get this error

serban-mihai avatar May 13 '21 06:05 serban-mihai

On my side, I was getting this error when I was conditionally calling the image src file as follow:

<Img src={isMini ? miniImg: bigImg} alt='logo' />

It starts working when I avoided this situation as follow:

{isMini ? <Img src={miniImg} alt='logo' /> : <Img src={bigImg} alt='logo' />}

I know It's repetitive, but It solved my problem.

coolbeatz71 avatar Aug 13 '21 10:08 coolbeatz71

It's frustrating and it needs to be fixed, but in the meantime, you could write this as a workaround:
If you were passing the ImgSrc data in some variable to your Img render function, such as

import LogoA from './images/logo.jpg';
const images = [LogoA, LogoB, ...];

// and rendering later:
<MyComponent src={images[0]} />

const MyComponent = (props) => <Img src={props.src} alt="xyz" className="abc" />

you will need to replace that with

import LogoA from './images/logo.jpg';
const images = [(p) => <Img src={LogoA} {...p} />, (p) => <Img src={LogoB} {...p} />, ...];

// and rendering later:
<MyComponent img={images[0]} />

const MyComponent = (props) => <props.img alt="xyz" className="abc" />

but I agree we need that babel plugin fixed :-D

Dalimil avatar Sep 10 '21 17:09 Dalimil

Hi, I am also getting the above error has anyone figured out a clear solution for this?

Mihai-github avatar Nov 05 '21 07:11 Mihai-github

Hi, I have the same problem. Is there any fixes for that?

scorn-da avatar Dec 06 '21 15:12 scorn-da

Same problem here and still no solution

anthonyjacquelin avatar Dec 14 '21 19:12 anthonyjacquelin

Hi, me too have the same problem. Is there any fixes for that?

moasko avatar Mar 08 '22 18:03 moasko

If you created your react app via create-react-app, you might have to rewire it to override the default bablerc https://www.npmjs.com/package/react-app-rewired

think-divergent avatar Apr 11 '22 16:04 think-divergent

same problem here.. how i wish there is noted as a known issue.. i could have save me time in the setup and then just facing this issue

ronjb04 avatar Apr 19 '22 21:04 ronjb04

Same Error

Shubhamrawat5 avatar May 23 '22 09:05 Shubhamrawat5

Hey people! Found the solution. https://youtu.be/3dzLIy8SPJg I've fully followed the instructions from here and it now works just fine the problem was the app wasn't reading the .babelrc file and that's the reason it had been showing the error "plugin not installed".

RuwaidMuntajim avatar Aug 17 '22 11:08 RuwaidMuntajim