cannot import image with create-react-app

前端 未结 5 1387
悲&欢浪女
悲&欢浪女 2021-02-18 21:43

I\'m using create-react-app, and I am struggling to load images. I am following the instructions as specified here, but I keep seeing the following error:



        
5条回答
  •  名媛妹妹
    2021-02-18 22:32

    Are you sure you've got the correct path? Also when you import an image via css (as is done in the example you mentioned) you need to give a path relative to the public folder and not the src folder. I have run into this problem several times.

    An example using import:

    import Image from './img.png'
    ...
    // react example
    ...
    render() {
        return (
             // notice the curly
    ...
    

    and not

    
    

提交回复
热议问题