简体   繁体   English

CSS React JS 中的模块无法正常工作,我几乎尝试了所有方法,但没有解决

[英]CSS Modules in React JS not working, i have tried literally everything but it didn't solved

Everything seems correct but I don't know why I can't able to use CSS in my project.一切似乎都是正确的,但我不知道为什么我不能在我的项目中使用 CSS。 I have tried without writing module in CSS file's name but it didn't work.我试过在 CSS 文件名中不写模块,但它没有用。 I have tried literally everything but none of those worked for me.我几乎什么都试过了,但没有一个对我有用。

import React, { Component } from 'react';
import styles from './App.module.css';

class App extends Component {

  render(){

     return (
        <div>
           <h1 className={styles.blue}>Burger Builder</h1>
        </div>
     );
  } 
}

export default App;

My CSS File,我的 CSS 文件,

.blue{
color: blue;
}

Package.json file Package.json 文件

{
   "name": "burger-builder",
   "version": "0.1.0",
   "private": true,
   "dependencies": {
     "@testing-library/jest-dom": "^5.14.1",
     "@testing-library/react": "^11.2.7",
     "@testing-library/user-event": "^12.8.3",
     "react": "^17.0.2",
     "react-dom": "^17.0.2",
     "react-scripts": "^1.1.5",
     "web-vitals": "^1.1.2"
   },
   "scripts": {
     "start": "react-scripts start",
     "build": "react-scripts build",
     "test": "react-scripts test",
     "eject": "react-scripts eject"
   },
   "eslintConfig": {
     "extends": [
       "react-app",
       "react-app/jest"
     ]
   },
   "browserslist": {
     "production": [
       ">0.2%",
       "not dead",
       "not op_mini all"
     ],
     "development": [
       "last 1 chrome version",
       "last 1 firefox version",
       "last 1 safari version"
     ]
   }
 }

Css Modules is related to react webpack config , which is hidden if you don't run nmp run eject . CSS Modules 与 react webpack config 相关,如果你不运行 nmp run eject ,它是隐藏的。

I think Probebly You need to Update your react-script to use css modules , Otherwise you should add some configuration to your webpackConfig , to support css modules ,我认为 Probebly 您需要更新您的 react-script 以使用 css modules ,否则您应该向您的 webpackConfig 添加一些配置,以支持 css modules ,

1-update your react script if Not worked => 2- check if your using cra config if it didn't worked =>3- npm run eject then change webpack config for css loaders . 1-如果不起作用,请更新您的反应脚本 => 2- 检查您是否使用 cra 配置,如果它不起作用 =>3- npm run eject 然后更改 css 加载器的 webpack 配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的切换器不工作。 我试过将 js cdn 放在顶部和底部,但没有用 - My toggler is not working. I have tried placing js cdn in top and bottom both but didn't work @Import 另一个 css 文件在我处理 Laravel 9 Inertia React 堆栈时不起作用 - @Import another css file didn't work when i'm working on Laravel 9 Inertia React stack 我需要一个带有可滚动主体的固定表头。 我已经尝试了一切,但似乎不起作用 - I need a fixed table header with a scrollable body. I have tried everything but it won't seem to work React 一直在说。map 不是 function 并且我尝试过的没有任何工作? - React keeps saying .map is not a function and nothing I have tried is working? Webpack:node_modules / css / index.js没有返回函数 - Webpack: node_modules/css/index.js didn't return a function 我们如何在angularJS中使用多个模块? 我已经努力了,一个正在工作,第二个没有工作 - How do we work with multiple modules in angularJS?? I have tried hard, one is working second one is not working 我尝试使用Js和CSS创建Tab,但它们无法正常工作 - I tried creating Tabs using Js and CSS but they won't work 我第一次创建了spring maven项目css,js,图片没有加载我试过这里给出的所有解决方案仍然没有工作 - I have create spring maven project for the first time css,js,images are not loading i have tried all solutions given here still not working React js 我如何使用 css 模块 - React js how can i use css modules 我尝试使用 .map function 但它对我的代码不起作用 - I tried to use the .map function but it didn't work on my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM