React中意外的令牌

React中意外的令牌

本文介绍了Webpack/React.js中的SyntaxError React中意外的令牌= {}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的.js文件之一中,我从Webpack中收到以下错误:

In one of my .js file, I'm getting the following error from Webpack:

  4 | export default function(ComposedComponent) {
  5 |   class Authentication extends Component {
> 6 |     static contextTypes = {
    |                         ^
  7 |       router: React.PropTypes.object
  8 |     }
  9 |

这些是我的依赖性:

  "devDependencies": {
    "babel-core": "^6.17.0",
    "babel-loader": "^6.2.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-preset-env": "^1.6.0",
    "babel-preset-react": "^6.16.0",
    "babel-preset-stage-3": "^6.24.1",
    "css-loader": "^0.26.1",
    "file-loader": "^1.1.4",
    "html-webpack-plugin": "^2.30.1",
    "image-webpack-loader": "^3.4.2",
    "rimraf": "^2.6.2",
    "style-loader": "^0.13.1",
    "url-loader": "^0.5.9",
    "webpack": "2.2.0-rc.0",
    "webpack-dev-server": "^2.2.0-rc.0"
  }

这是我的Webpack配置:

And this is my Webpack configuration:

{
  "presets": ["env", "react", "stage-3"],
  "plugins": ["transform-object-rest-spread"]
}

有人可以告诉我们缺少哪个插件或软件包吗?谢谢!

Could anybody tell which plugin or package is missing?Thank you!

推荐答案

类属性目前是第2阶段的提议,因此它不包含在babel-preset-env中.您可以:

Class properties is a stage 2 proposal at the moment, so it's not included in babel-preset-env. You can either:

  • 仅在.babelrc中包含此特定转换:

{ 插件":["transform-class-properties"]}

{ "plugins": ["transform-class-properties"]}

在第2阶段的所有提案中都包含:

include all stage 2 proposals with :

{ 预设":["env","react","stage-2"]}

{ "presets": ["env", "react", "stage-2"]}

在添加所有stage-2建议之前,请考虑风险: https://babeljs.io/docs/plugins/preset-stage-2/

Please consider the risks before adding all stage-2 proposals : https://babeljs.io/docs/plugins/preset-stage-2/

这篇关于Webpack/React.js中的SyntaxError React中意外的令牌= {}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 04:49