React with Material-UI 找不到模块

React with Material-UI can't find module

我想在我的 React 应用程序中显示 Material 按钮,但出现此错误:

Failed to compile.

./node_modules/@material-ui/core/styles/index.js
Module not found: Can't resolve '/Users/hugovillalobos/Documents/Code/LumiereProject/lumiere_frontend/node_modules/react-scripts/node_modules/babel-loader/lib/index.js' in '/Users/hugovillalobos/Documents/Code/LumiereProject/lumiere_frontend'

这是我的 App.js:

import React, { Component } from 'react';
import './App.css';
import LoginModal from './components/Login';

class App extends Component {
  render() {
    return (
      <div className="App">
        <LoginModal />
      </div>
    );
  }
}

export default App;

这是我的模块:

import React, { Component } from 'react';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';

class LoginModal extends Component {
  render() {
    return(
      <div>
        <Button variant="contained" className="{classes.Button}">
          Welcome to Lumiere...
        </Button>
      </div>
    );
  }
}

export default LoginModal;

一切正常,直到我尝试在我的应用程序中使用 Material 组件。也许我缺少安装某些东西,但我正在关注的 documentation 并不需要任何特别的东西。

仔细看报错信息,说找不到的模块是babel-loader ('/Users/hugovillalobos/Documents/Code/LumiereProject/lumiere_frontend/node_modules/react-scripts/node_modules/babel-loader/lib/index.js').

尝试运行 npm install --save babel-loader并再次编译。如果这不起作用,请尝试重新安装所有依赖项 npm ci 并再次编译。

我遇到了同样的错误。我安装了 Material-UI,而我的开发服务器仍然是 运行。重新启动服务器就可以了。我注意到有些软件包在您执行此操作之前不会“启动”。

重启服务器解决了我的问题