【问题标题】:react-router examples huge-apps: syntax unrecognized by webpackreact-router 示例巨大的应用程序:webpack 无法识别语法
【发布时间】:2016-06-02 05:06:13
【问题描述】:

这是错误信息:

ERROR in ./huge-apps/components/GlobalNav.js
Module build failed: SyntaxError: /home/yyangbian/workspace/react-router-examples/huge-apps/components/GlobalNav.js: Unexpected token (22:2)
  20 | 
  21 | styles.activeLink = {
> 22 |   ...styles.link,
     |   ^
  23 |   background: light,
  24 |   color: dark
  25 | }

以下是本地安装的依赖:

  "devDependencies": {
    "babel": "^6.5.2",
    "babel-core": "^6.5.2",
    "babel-loader": "^6.2.3",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "css-loader": "^0.23.1",
    "style-loader": "^0.13.0",
    "webpack": "^1.12.13",
    "webpack-dev-server": "^1.14.1"
  },
  "dependencies": {
    "react": "^0.14.7",
    "react-addons-css-transition-group": "^0.14.7",
    "react-dom": "^0.14.7",
    "react-router": "^2.0.0"
  }

webpack 配置文件与 git 仓库中的相同:webpack.config.js 下面是我的 .babelrc 文件:

{
  "presets": ["react", "es2015"]
}

【问题讨论】:

  • 你能把文件 ./huge-apps/components/GlobalNav.js 的内容贴到第 22 行吗

标签: reactjs webpack react-router babeljs


【解决方案1】:

对象剩余扩展语法(即您在样式对象中使用的...)不包含在 ES2015 Babel 预设中,因为它不是 ES2015 规范(或到目前为止的任何规范)的一部分。您需要安装object rest spread transform pluginstage 2 preset

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-07
    • 2016-05-16
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 2020-12-07
    相关资源
    最近更新 更多