You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React项目无法导入CSS文件的问题求助

React项目无法导入CSS文件的问题求助

大家好,我现在碰到一个头疼的问题——没法把CSS文件导入到JSX文件里,麻烦帮忙看看哪里出问题了😭

我在JSX文件里的导入代码如下,最后一行导入CSS的地方会报错:

import React from 'react';
import FormControl from '@material-ui/core/FormControl';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import Button from '@material-ui/core/Button';
import { Icon } from '@twilio/flex-ui';
import { makeInternalCall } from './index';
import '../../styling/theme1.css'; // 此处抛出错误

我已经在终端执行了下面的命令,安装了相关依赖:

npm install style-loader css-loader --save-dev

我的webpack.config.js配置是这样的:

module.exports = (config, { isProd, isDev, isTest }) => {
  /**
   * Customize the webpack by modifying the config object.
   * Consult https://webpack.js.org/configuration for more information
   */
  config.module.rules.push({
    test: /\.css$/,
    use: ['style-loader', 'css-loader'],
  });
  return config;
}

对应的Theme1.css内容:

.root {
  flex-grow: 1;
  display: flex;
  flex-wrap: wrap;
}

.main {
  margin: 0;
  padding: 0;
}

.formControl {
  width: 250px;
}

.boxDialpad {
  border-top: 1px solid #eeeeee;
}

.titleAgentDialpad {
  width: 100%;
  text-transform: uppercase;
  text-align: center;
  font-weight: bold;
  font-size: inherit;
}

.subtitleDialpad {
  text-transform: uppercase;
}

.buttonAgentDialpad {
  display: flex;
  justify-content: center;
}

.dialPadBtn {
  border-radius: 100px;
  min-width: 0px;
}

现在一运行项目就会报错,有没有大佬能帮我排查下问题出在哪呀?

备注:内容来源于stack exchange,提问作者Nui

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.23 15:27:48