使用 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是这样的
3 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
{
test: /\.(js|jsx|mjs)$/,
include: paths.appSrc,
loader: require.resolve('babel-loader'),
options: {
compact: true,
presets: ['es2015', 'react']
},
自己解决了,一个人干真难受
添加回答
举报
0/150
提交
取消