[英]Issues with the use of CSS modules in React
I am new to React and was learning how to use CSS modules in React but faced this error: 我是React的新手,正在学习如何在React中使用CSS模块,但遇到此错误:
Failed to compile.
./src/components/Header/Header.js
Module not found: Can't resolve './Header.module.css' in 'C:\Users\User\Desktop\qwerty\qwerty-project\src\components\Header'
Here is the code I am using 这是我正在使用的代码
import React from "react";
import styles from "./Header.module.css";
const header = props => {
return (
<div className="row">
<div className="col-md-4">
<i className="fab fa-github"></i>
</div>
<div className="col-md-8">
<nav>
<ul className={styles.nav}>
<li>{props.home}</li>
<li>{props.about}</li>
<li>{props.contact}</li>
</ul>
</nav>
</div>
</div>
);
};
export default header;
If you want to use the CSS file as a module you will need to use a webpack loader. 如果要将CSS文件用作模块,则需要使用webpack加载器。
Alternatively you can just import "./Header.module.css";
或者,您可以只
import "./Header.module.css";
and use the classnames to style your components 并使用类名对组件进行样式设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.