reactjs – Create-React-App无法编译|导入/第一个错误

前端之家收集整理的这篇文章主要介绍了reactjs – Create-React-App无法编译|导入/第一个错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在为我的个人网站使用Create-React-App.每次运行时我都会遇到以下错误
./src/~/react-router-dom/es/index.js
 Line 3:   Import in body of module; reorder to top  import/first
 Line 5:   Import in body of module; reorder to top  import/first
 Line 7:   Import in body of module; reorder to top  import/first
 Line 9:   Import in body of module; reorder to top  import/first
 Line 11:  Import in body of module; reorder to top  import/first
 Line 13:  Import in body of module; reorder to top  import/first
 Line 15:  Import in body of module; reorder to top  import/first
 Line 17:  Import in body of module; reorder to top  import/first
 Line 19:  Import in body of module; reorder to top  import/first
 Line 21:  Import in body of module; reorder to top  import/first
 Line 23:  Import in body of module; reorder to top  import/first
 Line 25:  Import in body of module; reorder to top  import/first

我当然觉得我错过了一些非常小的东西,但我很难搞清楚.我尝试使用Google搜索错误关键字’import / first’,这让我觉得这是一个ESLint问题.如果您在我的导入订单中发现任何问题,请告诉我.我尝试了不同的导入订单,但似乎没有什么可以摆脱错误.

import React from 'react';
import ReactDOM from 'react-dom';
import { createBrowserHistory } from 'history';
import { Router,Route,Redirect,Switch } from 'react-router-dom';
import './index.css'; 
import App from './App.js';
import Home from './home.js';
import About from './about.js';
import Contact from './contact.js';
import NotFound from './404.js';

import registerServiceWorker from './registerServiceWorker';

const history = createBrowserHistory();

ReactDOM.render(
    <Router history={history}>
        <App>
            <Switch>
                <Route exact path="/" component= {Home} />
                <Route path="/about" component= {About} />
                <Route path="/contact" component= {Contact} />
                <Route path="/404" component= {NotFound} />
                <Redirect to= "/404" />
            </Switch>
        </App>
    </Router>,document.getElementById('root')
);
registerServiceWorker();
这是因为您不小心将React Router安装到src文件夹中.所以linter认为这是你的代码并试图验证它.不要在src中安装第三方依赖项.

删除src / node_modules并在应用程序的根文件夹中运行npm install.如果缺少某个软件包,请在根文件夹中运行npm install –save< package-name>.

原文链接:https://www.f2er.com/react/301296.html

猜你在找的React相关文章