Webpacker: template react problem

Created on 3 Sep 2017  ·  5Comments  ·  Source: rails/webpacker

by generating application with : rails new myapp --webpack=react and following instructions
it will create hello_react.jsx file, where is listed to add following tag into layout
<%= javascript_pack_tag 'hello_react' %>
but it does not work (by loading a page it will show :
Uncaught Error: Module build failed: SyntaxError: Unexpected token (10:2)

8 |
9 | const Hello = props => (

10 |

Hello {props.name}!

| ^
11 | );
12 |
13 | Hello.defaultProps = {
.....

Most helpful comment

You would need to install react: bundle exec rails webpacker:install:react

All 5 comments

@PatrikRagan It seems the dependencies aren't installed correctly. Can you run yarn please? Also how does your .babelrc file looks?

yarn
yarn install v1.0.1
[1/4] 🔍 Resolving packages...
success Already up-to-date.
✨ Done in 0.65s.

{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}]
],

"plugins": [
"syntax-dynamic-import",
"transform-object-rest-spread",
["transform-class-properties", { "spec": true }]
]
}

You would need to install react: bundle exec rails webpacker:install:react

Thanks so much @gauravtiwari
Worked for me!

Thanks so much, @gauravtiwari. It worked

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eearslya picture Eearslya  ·  3Comments

eriknygren picture eriknygren  ·  3Comments

iChip picture iChip  ·  3Comments

naps62 picture naps62  ·  3Comments

suhomlineugene picture suhomlineugene  ·  3Comments