我試圖開始反應。我安裝了npm,browserify,babel和它的預設。 Babel無法轉換JSX代碼。任何人都可以幫助我理解發生了什麼。我使用正確的預設爲babel?我的demo.js意想不到的令牌與反應jsx和babel
"use strict";
var React = require('react');
var ReactDOM = require('react-dom');
var Test = React.createClass({
render: function(){
var {a, b, ...other} = this.props;
return(
<div>Hi</div>
);
}
});
這是我運行創建包的命令。
sudo browserify -t [ babelify --presets [ es2015 react ] ] src/demo.js -o ./bundle/app.js
以下是錯誤我得到
SyntaxError: /Users/shashank/git_views/srh_labs/webui/src/demo.js: Unexpected token (8:13)
6 | var Test = React.createClass({
7 | render: function(){
> 8 | var {a, b, ...other} = this.props;
| ^
9 | return(
10 | <div>Hi</div>
11 | );
at Parser.pp.raise (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.pp.unexpected (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/util.js:91:8)
at Parser.pp.parseIdentifier (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/expression.js:999:10)
at Parser.pp.parsePropertyName (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/expression.js:821:135)
at Parser.pp.parseObj (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/expression.js:737:12)
at Parser.pp.parseBindingAtom (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/lval.js:163:19)
at Parser.pp.parseVarHead (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/statement.js:591:18)
at Parser.<anonymous> (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/plugins/flow.js:953:13)
at Parser.parseVarHead (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/plugins/flow.js:953:13)
at Parser.pp.parseVar (/Users/shashank/git_views/srh_labs/webui/node_modules/babylon/lib/parser/statement.js:574:10)
$ sudo browserify -t [ babelify --presets [ es2015 react ] ] src/demo.js -o ../server/rest/src/main/webapp/uiserver/bundle/app.js
的可能的複製[巴別文件而不被轉化的複製](http://stackoverflow.com/questions/33440405/babel-file-被複制 - 沒有被轉換) – zerkms