react-lazy-load-image-component icon indicating copy to clipboard operation
react-lazy-load-image-component copied to clipboard

Named export 'LazyLoadImage' not found. The requested module 'react-lazy-load-image-component' is a CommonJS module, which may not support all module.exports as named expo rts.

Open aliiadev opened this issue 2 years ago • 14 comments

import { LazyLoadImage } from 'react-lazy-load-image-component'; ^^^^^^^^^^^^^ SyntaxError: Named export 'LazyLoadImage' not found. The requested module 'react-lazy-load-image-component' is a CommonJS module, which may not support all module.exports as named expo rts. CommonJS modules can always be imported via the default export, for example using:

import pkg from 'react-lazy-load-image-component'; const { LazyLoadImage } = pkg;

aliiadev avatar May 27 '23 02:05 aliiadev

import pkg from 'react-lazy-load-image-component'; const { LazyLoadImage } = pkg;

This will temporary solve this problem

yeasinsiam avatar Jul 20 '23 03:07 yeasinsiam

not correct, i tried many times, probably the problem is in production at astro, i used another library to fix it

aliiadev avatar Jul 20 '23 03:07 aliiadev

i am using react remix and it seems like working fine.

yeasinsiam avatar Jul 20 '23 03:07 yeasinsiam

import pkg from 'react-lazy-load-image-component'; const { LazyLoadImage } = pkg;

This will temporary solve this problem

Does not work for me, images do not load anymore

Niocas avatar Jul 24 '23 19:07 Niocas

import pkg from 'react-lazy-load-image-component'; const { LazyLoadImage } = pkg;

This will temporary solve this problem

Okay, it works for prerendering but if I run "npm run dev", it does show any images anymore, only works with prerendering for me

Niocas avatar Jul 24 '23 19:07 Niocas

如何解决?

Weibozzz avatar Aug 05 '23 08:08 Weibozzz

如何解决?

Please use another library

aliiadev avatar Aug 07 '23 07:08 aliiadev

Please use another library

Did find the one?

monolithed avatar Aug 23 '23 05:08 monolithed

The same error occurred when I deployed to Vercel

sisyphusla avatar Nov 06 '23 11:11 sisyphusla

with vite remix plugin:

  • does no work:
import pkg from 'react-lazy-load-image-component';
const { LazyLoadImage } = pkg
  • works:
import * as pkg from 'react-lazy-load-image-component';
const { LazyLoadImage } = pkg

🤷‍♂️

radandevist avatar Dec 12 '23 18:12 radandevist

Is it working now? I am using react for astro and it show the same error message

thefathdev avatar Jan 10 '24 03:01 thefathdev

Is it working now? I am using react for astro and it show the same error message

used another library to fix it

aliiadev avatar Jan 10 '24 03:01 aliiadev

Is it working now? I am using react for astro and it show the same error message

U can use react-lazy-load ` import React, {useCallback, useEffect, useState} from 'react'; import LazyLoad from 'react-lazy-load'; import type {ImgHTMLAttributes, ReactNode} from "react"; import loadingImage from '../../assets/loading-266.svg'

interface ZuImageProps extends ImgHTMLAttributes<HTMLImageElement> { placeholderZuLazy?: ReactNode; fallback?: string; }

const ZuImage = ({placeholderZuLazy, alt, width, height, fallback = '/assets/images/loading-266.svg', src, ...props}: ZuImageProps) => {

const [imgSrc, setImgSrc] = useState<string | undefined>(fallback || src)
const onError = () => setImgSrc(fallback)

const onLoad = useCallback(() => {
    setImgSrc(src);
}, [src]);

useEffect(() => {
    const img = new Image();
    img.src = src as string;
    img.addEventListener("load", onLoad);
    return () => {
        img.removeEventListener("load", onLoad);
    };
}, [src, onLoad]);

return (
    <LazyLoad className={'flex items-center justify-center'} width={width} height={height}>
    {/*// @ts-ignore */}
    <img src={imgSrc ? imgSrc : "/assets/images/chodienlogo.jpg"}  onError={onError} style={{maxHeight: '100%', objectFit: 'contain'}} {...props} alt={alt} width={width} height={height}/>
</LazyLoad>

) } export default ZuImage `

aliiadev avatar Jan 10 '24 03:01 aliiadev