Help us help you! Please choose one:
Getting this error on a simple React component.
- Rails 5.1
- react-rails
- webpacker
/app/javascript/components/Host.es6.jsx
Module build failed: SyntaxError: Unexpected token (4:16)
2 |
3 | class Host extends Component {
> 4 | renderHostRow = (host) => {
| ^
5 | return (
6 | <tr>
7 | <td></td>
@ ./app/javascript/components ^\.\/.*$
@ ./app/javascript/packs/application.js
@ multi (webpack)-dev-server/client?https://localhost:8080 ./app/javascript/packs/application.js
I updated /config/webpack/loaders/react.js to include React and ES2015 presets
module.exports = {
test: /\.(js|jsx)?(\.erb)?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
}
The actual component code is pretty straightforward
This is a component I simplified that works in a straight React application.
I removed the PropTypes, states, etc, and just got it down to simply render a table.
It still fails.
import React, { Component, PropTypes } from 'react';
class Host extends Component {
renderHostRow = (host) => {
return (
<tr>
<td>..hostname..</td>
<td>..user..</td>
<td>macOS {host.os_name}</td>
<td>{host.hardware_serial}</td>
</tr>
);
}
render() {
const { renderHostRow } = this;
const { hosts } = this.props;
return (
<table>
<thead>
<tr>
<th>Hostname</th>
<th>User</th>
<th>OS</th>
<th>Serial #</th>
</tr>
</thead>
<tbody>
{hosts.map((host) => {
return renderHostRow(host);
})}
</tbody>
</table>
);
}
}
export default Host;
Any ideas would be greatly appreciated.
Help us help you! Please choose one:
react-railswith another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working.Getting this error on a simple React component.
I updated
/config/webpack/loaders/react.jsto include React and ES2015 presetsThe actual component code is pretty straightforward
This is a component I simplified that works in a straight React application.
I removed the PropTypes, states, etc, and just got it down to simply render a table.
It still fails.
Any ideas would be greatly appreciated.