模块构建失败了

时间:2017-12-23 16:46:37

标签: javascript node.js reactjs ecmascript-6 babeljs

我通过express-generator(表达myNewApp)创建了MERN(MongoDB,ExpressJS,React,Node)项目。

在反应组件内部,我有这段ES6代码

GridView

当我运行npm start时出现此错误:模块构建失败:SyntaxError:意外的令牌(53:13)。

这是我的package.json:{

onChange = (event, { newValue }) => { // FYI this is line 53
        this.setState({
            value: newValue
   });
};

}

我的webpack配置文件如下所示。

"name": "myNewApp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "webpack --progress --colors --watch -d",
    "build": "webpack --progress --colors -p"
  },
  "dependencies": {
    "axios": "^0.15.3",
    "babel-cli": "^6.11.4",
    "babel-core": "^6.13.2",
    "babel-preset-es2015": "^6.13.2",
    "babel-preset-react": "^6.11.1",
    "body-parser": "~1.16.0",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.0",
    "ejs": "^2.5.6",
    "express": "~4.14.1",
    "jade": "~1.11.0",
    "mongojs": "^2.4.0",
    "morgan": "~1.7.0",
    "react": "^15.4.2",
    "react-autosuggest": "^9.3.2",
    "react-bootstrap": "^0.30.7",
    "react-dom": "^15.4.2",
    "react-router": "^2.6.1",
    "serve-favicon": "~2.3.2"
  },
  "devDependencies": {
    "babel-loader": "^6.2.10",
    "http-server": "^0.9.0",
    "webpack": "^1.13.3"
  }

2 个答案:

答案 0 :(得分:0)

onChange = ...是一个类属性赋值,为了让您的代码使用Babel进行转换,您需要npm install --save-dev babel-plugin-transform-class-properties,然后调用.babelrc文件中的插件,请参阅{{3}有关详细信息。

答案 1 :(得分:0)

  1. npm i --save-dev babel-preset-stage-0
  2. 更改webpack.config.js:query: { presets: ['react', 'es2015', 'stage-0']