猿问

react build时报错:syntax error: Unexpected token

使用 npm start命令运行正常,使用npm run build执行会报错如下:

syntax error: C:/Users/wenji/Desktop/my-react-app/src/index.js:
Unexpected token (26:6)

我的index.js:

import React, { Component } from 'react';

import ReactDOM from 'react-dom';

import './index.css';

import registerServiceWorker from './registerServiceWorker';

import './App.css';

import Chat from './chat/index';

import Login from './login/index'

import {

  BrowserRouter as Router,

  Route,

  Switch

} from 'react-router-dom';


import { Provider} from 'react-redux'

import store from './store'


// const Home = () => (

//   <div>

//     <h3>Home</h3>

//   </div>

// )

class App extends Component{

  render(){

    console.log(Router)

    return (

      <Router >

      <div style={{height:'100%'}}>

      <Switch>

        <Route exact path="/" component={Login}/>

        <Route path="/chat" component={Chat}/>

        {/* <Route path="/home" component={Home}/> */}

        <Route path="/login" component={Login}/>

      </Switch>

      </div>

    </Router>)

  }

}



ReactDOM.render(

  <Provider store={store}>

  <App />

  </Provider>,

  document.getElementById('root'));

registerServiceWorker();

看起来像是jsx语法没有被正确的转化,我的webpack.config.build是这样的

https://img.mukewang.com/5c961f6b0001998d03820799.jpg

https://img4.mukewang.com/5c961f800001182605230494.jpg

慕娘9325324
浏览 3072回答 3
3回答

慕工程0101907

&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; test: /\.(js|jsx|mjs)$/,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include: paths.appSrc,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader: require.resolve('babel-loader'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; compact: true,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; presets: ['es2015', 'react']&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },自己解决了,一个人干真难受

慕的地10843

没遇到过不过我建议换成babel
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答