加载图片png文件以响应应用时出错

问题描述 投票:0回答:2

获取Error: Cannot find module 'schema-utils'当尝试导入图像时,似乎有点奇怪,我尝试从公共目录以及直接在Header component文件夹中导入并得到相同的错误。这是我的代码

import React from "react";
import "../styles/Header.css";
import title from "./insta-title.png";

export default function Header() {
  return (
    <div className="head">
      <header>
        <img src={title}></img>
      </header>
    </div>
  );
}

javascript reactjs
2个回答
0
投票

img标记中的反应是这样写的[[,因此,请编辑代码,如下所示:

import React from "react"; import "../styles/Header.css"; import title from "./insta-title.png"; export default function Header() { return ( <div className="head"> <header> <img src={title}/></header> </div> );

0
投票
[不幸的是,我没有足够的声誉来发表评论。我建议您在项目中安装eslint。这里的更多详细信息:https://eslint.org绝对可以帮助您避免此类问题。

Find Problems ESLint statically analyzes your code to quickly find problems. ESLint is built into most text editors and you can run ESLint as part of your continuous integration pipeline.

Fix Automatically
Many problems ESLint finds can be automatically fixed. ESLint fixes are syntax-aware so you won't experience errors introduced by traditional find-and-replace algorithms.
Customize
Preprocess code, use custom parsers, and write your own rules that work alongside ESLint's built-in rules. You can customize ESLint to work exactly the way you need it for your project.

祝你好运!
© www.soinside.com 2019 - 2024. All rights reserved.