[英]Module not found: Can't resolve '../images/bg-header-desktop.svg' when importing image into React project
I am building a React project and I am having difficulties in importing a background image.我正在构建一个 React 项目,但在导入背景图像时遇到了困难。 I am getting the error above.我收到上面的错误。 The image is in an images folder which is in a public folder.该图像位于公共文件夹中的图像文件夹中。 This is my structure of the app.这是我的应用程序结构。
The image is bg-header-desktop.svg.图像是 bg-header-desktop.svg。 This is how I want it to look like.这就是我想要的样子。 The code I have for the component is the following:我为该组件提供的代码如下:
import React from "react";
import "./heading.styles.css";
const Heading = () => (
<header>
<div className="top-background">
</div>
</header>
);
export default Heading;
My css looks like this this:我的 css 看起来像这样:
.top-background {
height: 155px;
background-image: url(../images/bg-header-desktop.svg);
background-color: #5da4a4;
margin-bottom: 70px;
}
This is how I would like it look.这就是我想要的样子。 Any help would be appreciated.任何帮助,将不胜感激。
It should be like this应该是这样的
.top-background {
height: 155px;
background-image: url("/images/bg-header-desktop.svg");
background-color: #5da4a4;
margin-bottom: 70px;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.