I create a Next app using typescript and tailwindcss i am unable to display my Image location in Public/assests/images/me/me.png i also created a types folder in which i created a images.d.ts file
import React from 'react';
import MyImage from "@/public/assets/images/me/me.png";
console.log(MyImage);
function Profile() {
return (
<div className='flex items-center gap-x-2 transition-colors duration-75 text-primary-foreground'>
{/* photo */}
<div className='relative w-[100px] h-[100px] rounded-full flex justify-center items-center bg-gradient-to-r from-blue-joust to-green-benzol'>
<img src={MyImage} alt='Sujeet Photo' className='w-[95px] h-[95px] border-[0.2vw] border-blue-cosmos rounded-full object-cover'/>
{/* Online */}
<div className='w-3 h-3 rounded-full bg-green-benzol border-blue-cosmos absolute right-0 bottom-5'></div>
</div>
<div className="text-3xl font-medium">SUJEET SINGHANIYA</div>
</div>
)
}
export default Profile;
3
Answers
You should use
MyImage.src
instead of directly using the static importMyImage
itself.But in next.js, a better approach would be to use the
Image
component, which can directly useMyImage
itself:Nextjs provides an image component, try to use that for image optimization(Also recommended by the Nextjs itself). Comes from next/image, import it and use it.
here you can show you image like it is because you are using html img tag so do it like no need to import