Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

javascript - babel watch SyntaxError: Unexpected token

When I uses babel to watch a jsx file. But there is a syntax error.

Before that, I uses react-tools to watch, and everything is fine.

SyntaxError: assets/js/chat/chat.jsx: Unexpected token (258:16)
  256 |         if (this.props.isOpen) {
  257 |             return (
> 258 |                 <div className="modal-overlay">
      |                 ^
  259 |                     <ReactCSSTransitionGroup transitionName={this.props.transitionName}>
  260 |                         <div className="chat-modal">
  261 |                             {this.props.children}

The following is my code.

var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var Modal = React.createClass({
    render: function() {
        if (this.props.isOpen) {
            return (
                <div className="modal-overlay">
                    <ReactCSSTransitionGroup transitionName={this.props.transitionName}>
                        <div className="chat-modal">
                            {this.props.children}
                        </div>
                    </ReactCSSTransitionGroup>
                </div>
            )
        } else {
            return <div className="modal-overlay"><ReactCSSTransitionGroup transitionName={this.props.transitionName}/></div>
        }
    }
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I had a similar issue the other day. It seems that babel now needs some additional plugins to work with react.

See the answer in this SO question: babel-loader jsx SyntaxError: Unexpected token


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...