代码之家  ›  专栏  ›  技术社区  ›  Majedur

节点.js-SyntaxError:添加react视图后意外的令牌导入

  •  0
  • Majedur  · 技术社区  · 7 年前

    显示代码

    (function (exports, require, module, __filename, __dirname) { import React, { Component } from 'react';
    

    SyntaxError: Unexpected token import
        at createScript (vm.js:80:10)
        at Object.runInThisContext (vm.js:139:10)
        at Module._compile (module.js:616:28)
        at Object.Module._extensions..js (module.js:663:10)
        at Module.load (module.js:565:32)
        at tryModuleLoad (module.js:505:12)
        at Function.Module._load (module.js:497:3)
        at Function.Module.runMain (module.js:693:10)
        at startup (bootstrap_node.js:191:16)
        at bootstrap_node.js:612:3
    

    我的api和nodejs和expressjs运行良好。添加react视图后,显示错误。我的应用程序js

    import React, { Component } from 'react';
    import Header from './components/Header';
    import { Switch, Route } from 'react-router-dom'
    import Feed from './components/Feed'
    import Profile from './components/Profile'
    import ArticleView from './components/ArticleView'
    import Editor from './components/Editor'
    import requireAuthentication from './utils/requireAuth'
    import SignInWith from './components/SignInWith'
    //import  from './components'
    
    class App extends Component {
        render() {
            const pathname = window.location.pathname
            return ( 
                <div>
                { !pathname.includes('editor') ? <Header /> : '' }
                <SignInWith />
                    <Switch>
    
                        <Route exact path="/" component={Feed} />
                        <Route path="/profile/:id" component={Profile} />
                        <Route path="/articleview/:id" component={ArticleView} />
                        <Route path="/editor" component={requireAuthentication(Editor)} />
                        <Route path="**" component={Feed} />
                    </Switch>
                </div>
            );
        }
    }
    
    export default App;
    

    任何帮助都将不胜感激

    0 回复  |  直到 7 年前
    推荐文章