The worm The worm - 1 month ago 6
React JSX Question

React error even though syntax is correct

I have removed all my code down to the point I just have this:

export class DateApp extends React.Component {
render() {
return (
<div className="dateApp">
<h1> Comments </h1>
</div>
);
}
};
export default DateApp;


I get this error on this line:

Module build failed: SyntaxError: Unexpected token


point to the
<
on the first
<div>


I thought it may be a syntax error in one of my functions but as I have removed them all it cant be that.
I have babel, react all installed etc.

Answer

If you're using babel to transpile to code:

In the root of your project change the .babelrc file to include the react preset:

{
  "presets": [
    "es2015",
    "react"
  ]
}

Install the babel react preset using NPM:

npm install --save-dev babel-preset-react
Comments