Webpack在运行命令时显示语法错误

时间:2016-08-27 18:30:52

标签: javascript reactjs

大家好我想跟踪一个反应js的视频我正在开发一个看到该教程的应用程序。遇到了语法错误,无法找到任何解决方案.Below是我的代码: app.js:

var React = require('react');

var APP = React.createClass({
    render(){
       return (<h1>Hello World from React</h1>);
    }
});

module.exports = APP;

APP-server.js

var express = require('express');

var app = express();

app.use(express.static('./public'));
app.use(express.static('./node_modules/bootstrap/dist'));

app.listen(3000);
console.log("Polling server is running at 'http://localhost:3000'");

APP-client.js

var React = require('react');
var APP = require('./components/app');

React.render(<APP />, document.getElementById('react-container'));

webpack.config.js

module.exports = {
entry: "./app-client.js",
output: {
    filename: "public/bundle.js"
},
module: {
    loaders: [
        {
            exclude: /(node_modules|app-server.js)/,
            test: /.jsx?$/,
            loader: 'babel-loader',
            query: {                 
                presets: ['es2015', 'react', 'stage-0']
            }
        }
    ]
}

};

命令行出错:

$ webpack
Hash: efea76b1048c3a97b963
Version: webpack 1.13.2
Time: 2344ms
+ 1 hidden modules

ERROR in ./app-client.js
Module build failed: SyntaxError: C:/Users/Sanjay/Documents/node_project/start/app-client.js: Unexpected token (4:13)

2 | var APP = require('./components/app');
3 |
> 4 | React.render(<APP />, document.getElementById('react-container'));
|              ^

任何帮助都会让我感激不尽。

1 个答案:

答案 0 :(得分:0)

我在使用最新的webpack(1.13.2)和ReactDOM.render()的不同操作系统(Linux)上遇到了同样的错误。这个项目已经在使用以前安装的节点模块的另一个目录中工作,所以我目前怀疑这是我的一个dev-dependencies中的一个紧急错误。