index.js中超出了最大调用堆栈大小

时间:2018-02-06 11:44:44

标签: javascript reactjs debugging

我创建了一个完全符合要求的反应应用程序但是在localhost上运行web应用程序时,页面保持加载而不呈现任何内容。除此之外,我还在Visual Studio代码中显示错误,显示"maximum call stack size exceeded in index.js"。这是index.js文件和与之关联的其他文件。

import React from 'react';
import ReactDOM from 'react-dom';
import AppRouter from './routers/AppRouter';

ReactDOM.render(<AppRouter />, document.getElementById('root'));

这是另一个位于文件夹路由器中的文件。

import React from 'react';
import {BrowserRouter,Route,Switch} from 'react-router-dom';
import ExpenseDashboardPage from '../components/ExpenseDashboardPage.js';
import AddPage from '../components/AddPage.js';
import EditPage from '../components/EditPage.js';
import HelpPage from '../components/HelpPage.js';
import NotFoundPage from '../components/NotFoundPage.js'
import Header from '../components/Header.js'


console.log("working ");
    const AppRouter = ()=>(
        <BrowserRouter>
        <div>
        <Header/>
        <Switch>
         <Route path="/" component={ExpenseDashboardPage} exact={true}/>
         <Route path="/create" component={AddPage}/>
         <Route path="/edit/:id" component={EditPage} exact={true}/>
         <Route path="/help" component={HelpPage} exact={true}/>
         <Route  component={NotFoundPage}/>
        </Switch>
        </div>
        </BrowserRouter>
    );

    export default AppRouter;

我正在更新我可以在visual studio代码上看到的调试器控制台。

    Debugger listening on ws://127.0.0.1:47583/31bb1f1c-c7f5-49e3-82e6-ecbefb58d193
SyntaxError: Unexpected token import
vm.js:80
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Debugger attached.
e:\demo\src\routers\AppRouter.js:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
                                                              ^^^^^^

SyntaxError: Unexpected token import
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
Waiting for the debugger to disconnect...

1 个答案:

答案 0 :(得分:0)

您可能会因为index.js中的某些内容具有循环依赖关系而得到此错误 - 函数调用函数b,但函数b调用函数a。

它可以是组件的渲染调用,并且该组件包含其自己的父组件,例如。

调试器是一个很好的建议,有关于如何使用它的在线教程,你可以从我在评论中提到的SO帖子开始。这是:What is a debugger and how can it help me diagnose problems?