The create-react-app imports restriction outside of src directory

前端 未结 17 1918
时光说笑
时光说笑 2020-11-22 13:20

I am using create-react-app. I am trying to call an image from my public folder from a file inside my src/components. I am receiving this error message.

17条回答
  •  佛祖请我去吃肉
    2020-11-22 13:39

    You can try using simlinks, but in reverse.

    React won't follow simlinks, but you can move something to the source directory, and create a simlink to it.

    In the root of my project, I had a node server directory that had several schema files in it. I wanted to use them on the frontend, so I:

    • moved the files /src
    • in the termal, I cd'ed into where the schema files belonged in server
    • ln -s SRC_PATH_OF_SCHEMA_FILE

    This gave react what it was looking for, and node was perfectly happy including files through simlinks.

提交回复
热议问题