REFERENCE Image from asset folder in react spfx

Gerald Nduaguba 1 Reputation point
2022-05-16T19:14:30.977+00:00

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

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-05-17T02:47:12.547+00:00

    Hi @Gerald Nduaguba ,
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.