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 = {
.....
@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
Most helpful comment
You would need to install react:
bundle exec rails webpacker:install:react