不知道为什么会出现错误,这是我的 index.js 和 App.js(默认导出)。我在 app.js 中使用了导出默认值。
索引.js:
import "./index.css";
import App from "./App";
import "bootstrap/dist/css/bootstrap.css";
import "font-awesome/css/font-awesome.css";
<App />;
Run Code Online (Sandbox Code Playgroud)
应用程序.js
import React, { Component } from "react";
import { ToastContainer } from "react-toastify";
import NavBar from "../components/navBar";
import auth from "../services/authService";
import "react-toastify/dist/ReactToastify.css";
import "./App.css";
class App extends Component {
state = {};
componentDidMount() {
const user = auth.getCurrentUser();
this.setState({ user });
}
render() {
const { user } = this.state;
return (
<React.Fragment>
<ToastContainer />
<NavBar user={user} />
</React.Fragment> …Run Code Online (Sandbox Code Playgroud) 我的 App.js(经过简化但仍然会出现这么多错误。)
import React, { Component } from "react";
class App extends Component {
state = {};
componentDidMount() {
this.setState({ user });
}
}
export default App;
Run Code Online (Sandbox Code Playgroud)
我现在更新了我的 index.js:
import React from "react";
import { BrowserRouter } from "react-router-dom";
import App from "./App";
const Index = () => (
<BrowserRouter>
<App />
</BrowserRouter>
);
export default Index;
Run Code Online (Sandbox Code Playgroud)
它给出了错误 Invariant failed: Browser history needs a DOM
[ error ] ./node_modules/font-awesome/css/font-awesome.css 7:0
Module parse failed: Unexpected character '@' (7:0)
You may need an appropriate loader to handle this file type, currently no loaders are
configured to process this file. See https://webpack.js.org/concepts#loaders
| /* FONT PATH
| * -------------------------- */
> @font-face {
| font-family: 'FontAwesome';
| src: url('../fonts/fontawesome-webfont.eot?v=4.7.0');
Run Code Online (Sandbox Code Playgroud)
我已经安装了 next-css,我的 next.config.json 是:
const withCSS = require("@zeit/next-css");
module.exports = withCSS({});
Run Code Online (Sandbox Code Playgroud)