In my React setup, I have the following devdependencies in the package.json file -
"devDependencies": {
"@babel/core": "^7.0.0-beta.53",
"@babel/preset-env": "^7.0.0-beta.53",
"@babel/preset-react": "^7.0.0-beta.53",
"babel-core": "^6.26.3",
"babel-loader": "^8.0.0-beta.4",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.16.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"webpack-merge": "^4.1.3"
}
I was trying out couple of ways to get the babel setup to work and this is what I noticed. If I have the below .babelrc file it works fine -
{
"presets": ["@babel/preset-env","@babel/preset-react"]
}
However, if I have the preset with the most basic setting as mentioned in the babel docs it errors out.
{
"presets": ["env"]
}
I get the Syntax Error: Unexpected token at the of my index.js file. Link to another docs mentions this -
We don't recommend using preset-env this way because it doesn't take advantage of its ability to target specific browsers.
Why does the recommended approach error out here? Something wrong with my devDependencies?
Error message:
> ERROR in ./src/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/XXXXXX//src/index.js: Unexpected token (7:4)
5 | const App = () => {
6 | return (
7 | <div>
| ^