ための "予期しないトークン" 私はtranspileしようとしたコードはこれです:ガルプ+ browserify + babelify:JSXコード
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
gulp.task('default', function() {
return browserify('./source/app.js')
.transform(babelify)
.bundle()
.pipe(source('snapterest.js'))
.pipe(gulp.dest('./build/'));
});
しかし、私場合:
var React = require('react');
var ReactDOM = require('react-dom');
var listOfItems = <ul>
<li className="item-1">Item 1</li>
<li className="item-2">Item 2</li>
<li className="item-3">Item 3</li>
</ul>;
ReactDOM.render(listOfItems, document.getElementById('react-application'));
gulpfile.jsは次のようになりますgulp
を起動しようと、それは私に、このエラーを与える:
[18:00:34] Using gulpfile ~/Documents/Esercitazioni/react/reactjs-essentials/snapterest/gulpfile.js
[18:00:34] Starting 'default'...
events.js:141
throw er; // Unhandled 'error' event
^
SyntaxError: /Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/source/app.js: Unexpected token (4:18)
2 | var ReactDOM = require('react-dom');
3 |
> 4 | var listOfItems = <ul>
| ^
5 | <li className="item-1">Item 1</li>
6 | <li className="item-2">Item 2</li>
7 | <li className="item-3">Item 3</li>
at Parser.pp.raise (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/location.js:22:13)
at Parser.pp.unexpected (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/util.js:91:8)
at Parser.pp.parseExprAtom (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:512:12)
at Parser.pp.parseExprSubscripts (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:270:19)
at Parser.pp.parseMaybeUnary (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:250:19)
at Parser.pp.parseExprOps (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:180:19)
at Parser.pp.parseMaybeConditional (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:157:19)
at Parser.pp.parseMaybeAssign (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/expression.js:120:19)
at Parser.pp.parseVar (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:585:24)
at Parser.pp.parseVarStatement (/Users/macbookpro/Documents/Esercitazioni/react/reactjs-essentials/snapterest/node_modules/babelify/node_modules/babel-core/node_modules/babylon/lib/parser/statement.js:416:8)
いいえ! :[私に同じエラーを与える! –
JSXを使わずにJavaScriptコードを使って同じコードを書くと、gulpはエラーを表示しません。 JSXのgulpのみを使用するとエラーになります。 –
ああ、あなたのbabelifyが反応構文をサポートするように正しく構成されていないと思います。私はベルベリファの専門家ではないので、私はそれを最もよく修正する方法がわかりません –