2

Tried every path but the images are not importing locally from images folder.

Error - "Module not found: Can't resolve '../images/banner1.jpg'"

Images folder path

Accessing images in ImagesSlider.js file. components/Banner/Imageslider.js

ImagesSlider.js file

 import Image from 'next/image';
 import Slider from "react-slick";

 import "slick-carousel/slick/slick.css";
 import "slick-carousel/slick/slick-theme.css";
 import banner1 from '.../images/banner1.jpg';
 import banner2 from '.../images/banner2.jpg';
 import banner3 from '.../images/banner3.jpg';
 import banner4 from '.../images/banner4.jpg';


   export default function ImageSlider() {

   var settings = {
    dots: true,
    infinite: true,
    speed: 500,
    slidesToShow: 1,
    slidesToScroll: 1,
    autoplay: true,
  };
  return (
   <Slider  {...settings}>

     <Image  className='rounder-md px-5' src={banner1} 
            width={700} height={400} />

    <Image className='rounder-md px-5' src={banner2} 
            width={700} height={400} />

    <Image className='rounder-md px-5' src={banner3} 
            width={700} height={400} />
    
    <Image className='rounder-md px-5' src={banner4} 
            width={700} height={400} />

   </Slider>
  )
  }


 .next.config.js file

    const withImages = require('next-images')
    module.exports = withImages({})

1 Answer 1

2

There is no need to load the image via the import if you add the images to /static/

You can use like this <img src={require('./yourImage.jpg')} />

Example:

export default () => (
  <div>
    <img src={require('./images/your-image.jpg')} />
  </div>
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.