Tags

,

Problem:
If you’ve encounter an error that says Unexpected token and it points to < character E.g:

ERROR in ./src/index.js
Module build failed: SyntaxError: C:/_react/react-post/src/index.js: 
Unexpected token (11:17)
> 11 |  ReactDOM.render(<div>Hello world</div>, document.getElementById('root'))
...

Solution:
Check your package.json if you have babel-preset-react. If none then we need to install it.
npm install –save-dev babel-preset-react
Next in your .babelrc, we need to add the “react” preset. E.g.

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