Reactjs 如何修复模块解析失败:意外令牌?

Reactjs 如何修复模块解析失败:意外令牌?,reactjs,npm,webpack,react-router,node-modules,Reactjs,Npm,Webpack,React Router,Node Modules,当我运行npm run build时,我遇到了以下错误: ERROR in ./src/client.js 7:2 Module parse failed: Unexpected token (7:2) File was processed with these loaders: * ./node_modules/jshint-loader/index.js You may need an additional loader to handle the result of these load

当我运行
npm run build
时,我遇到了以下错误:

ERROR in ./src/client.js 7:2
Module parse failed: Unexpected token (7:2)
File was processed with these loaders:
 * ./node_modules/jshint-loader/index.js
You may need an additional loader to handle the result of these loaders.
| 
| const component = (
>   <Router history={browserHistory}>
|     {routes}
|   </Router>
 @ multi babel-polyfill ./src/client.js main[1]
我怎样才能修好它

反应:16.13.0

网页:4.42.0

净现值:6.14.2

webpack config.js

global.Promise=require('bluebird');
const webpack=require('webpack');
const path=require('path');
常量插件=[
新的webpack.DefinePlugin({
“process.env”:{
浏览器:JSON.stringify(true),
NODE_ENV:JSON.stringify(process.ENV.NODE_ENV | |“development”)
}
})
];
module.exports={
条目:['babel-polyfill','./src/client.js'],
输出:{
文件名:“bundle.js”,
path:path.resolve(uu dirname,'dist')
},
模块:{
规则:[{
测试://\.js$/,//include.js文件
强制执行:“pre”,//预加载jshint加载程序
排除:/node\u modules/,//排除node\u modules文件夹中的所有文件
使用:[{
加载器:“jshint加载器”,
//可选jshint对象中的更多选项
选项:{//⬅ 形式化jshint属性
camelcase:是的,
错误:错误,
失败提示:false
}
}]
}]
}
};

您的网页配置无法处理React的JSX语法。您需要使用一些加载程序对其进行更新才能使其正常工作(这里有一个教程:)


我建议您首先使用CreateReact应用程序,它将所有这些配置抽象出来:。以这种方式使用react更容易,您可以在准备好/需要时自定义它。

您的网页配置不处理react的JSX语法。您需要使用一些加载程序对其进行更新才能使其正常工作(这里有一个教程:)


我建议您首先使用CreateReact应用程序,它将所有这些配置抽象出来:。以这种方式开始react会更容易,您可以在准备好/需要时自定义它。

您的网页配置是什么?@tudor.gergely我添加到了帖子中,请检查您的网页配置是什么?@tudor.gergely我添加到了帖子中,请检查
import React      from 'react';
import ReactDOM   from 'react-dom';
import { browserHistory, Router } from 'react-router';
import routes from './routes';

const component = (
  <Router history={browserHistory}>
    {routes}
  </Router>
);

ReactDOM.render(component, document.getElementById('react-view'));