【问题标题】:Babel configuration to run a redux+react JSBin example. Unexpected token error运行 redux+react JSBin 示例的 Babel 配置。意外的令牌错误
【发布时间】:2016-07-06 17:54:15
【问题描述】:

尝试为此 JSBin 设置 Babel 环境: https://jsbin.com/taquke/edit?js,output

这是我的 package.json:

{
  "name": "babel",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-cli": "^6.10.1",
    "babel-plugin-transform-object-rest-spread": "^6.8.0",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-react": "^6.11.1"
  }
}

这是我的 .babelrc:

    {
      "presets": ["es2015", "react"],
      "plugins": ["transform-object-rest-spread"],
      "env": {
        "development": {

        }
      }
    }

+我已经为 WebStorm(给 babel)定义了一个文件观察器。

我在保存 JS 文件时得到这个:

有什么想法吗?

【问题讨论】:

  • 语法不一样,不是吗,那里有个等号
  • 你的也有一个等号,这就是它崩溃的地方......
  • 无论如何,这个问题的答案就是你的问题的答案..你需要正确的 babel 转换/插件来处理类箭头属性
  • babel-preset-es2015 应该涵盖这一点。

标签: reactjs ecmascript-6 redux babeljs


【解决方案1】:

Class properties 不是 ES2015 的一部分。

如果您想直接在类定义中定义属性,您应该启用babel-plugin-transform-class-properties 或整个babel-preset-stage-1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-01
    • 2016-11-23
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2016-08-24
    • 2016-12-04
    相关资源
    最近更新 更多