fedosejev / react-essentials

Supporting React.js Essentials book readers.
http://reactessentials.com
219 stars 90 forks source link

unexpected token #85

Open samsond opened 8 years ago

samsond commented 8 years ago

when i tried running gulp i have got the below error, events.js:160 throw er; // Unhandled 'error' event ^

SyntaxError: /Users/samsonhailu/project/sandbox/reactessential/snapterest/source/app.js: Unexpected token (4:18) 2 | var ReactDOM = require('react-dom'); 3 |

4 | var listOfItems =

    | ^ 5 |
  • Item 1
  • 6 |
  • Item 2
  • 7 |
  • Item 3
  • at Parser.pp.raise (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/location.js:22:13) at Parser.pp.unexpected (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/util.js:89:8) at Parser.pp.parseExprAtom (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/expression.js:522:12) at Parser.pp.parseExprSubscripts (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/expression.js:277:19) at Parser.pp.parseMaybeUnary (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/expression.js:257:19) at Parser.pp.parseExprOps (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/expression.js:188:19) at Parser.pp.parseMaybeConditional (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/expression.js:165:19) at Parser.pp.parseMaybeAssign (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/expression.js:128:19) at Parser.pp.parseVar (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/statement.js:601:24) at Parser.pp.parseVarStatement (/Users/samsonhailu/project/sandbox/reactessential/snapterest/node_modules/babylon/lib/parser/statement.js:424:8)

but when i compile it using jsx --watch source/ build/ ... it compiles successfully. i didn't know the reason why it failed?

vladsoroceanu commented 8 years ago

Hi,

Before you fixed it what where you using in your gulpfile to compile the react template?

ioan-ghisoi-cko commented 7 years ago

For the current version of Babelify the syntax in the book is not supported but there is a quick fix:

1) inside /snapterest do npm install --save-dev babel-preset-react 2) inside /snapterest do npm install --save-dev babel-preset-es2015 babel-preset-react 2) replace: this :
.transform(babelify) .transform(babelify) with this : .transform(babelify.configure({ presets: ["es2015", "react"] })) Shout out for wphampton for this ( https://github.com/babel/babelify/issues/126 )