question

GeraldNduaguba-4428 avatar image
0 Votes"
GeraldNduaguba-4428 asked RaytheonXie-MSFT commented

REFERENCE Image from asset folder in react spfx

Please how do i reference the image from an asset folder in my react spfx project.

I keep getting an error when i run it

202395-screenshot-586.png


Below is a snapshot of my code

202411-screenshot-589.png


office-sharepoint-onlinesharepoint-dev
screenshot-586.png (240.5 KiB)
screenshot-589.png (184.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered RaytheonXie-MSFT commented

Hi @GeraldNduaguba-4428 ,
You can refer to following steps to require png file.
Create index.d.ts file in folder src,and add this line

 declare module '*.png';

Then add "include": ["./src/index.d.ts"] inside tsconfig.json, after "compilerOptions" : {...}.


===================================
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @GeraldNduaguba-4428 ,
Have you tried the solution I proposed?

If you have any questions or progress, you can contact me in time.

Looking forward to your reply

Have a lucky day!

Thanks,
Raytheon Xie

0 Votes 0 ·

Hi @GeraldNduaguba-4428 ,
Would you tell me whether your issue has been resolved or have any update?
I am looking forward to your reply.

Have a nice day!

Thanks,
Raytheon Xie

0 Votes 0 ·