.babelrc not working
See original GitHub issueI have folled a very simple tutorial to set up webpack, babel and react, but get an error with the presets when I use a .babelrc
file.
webpack.config.js:
var path = require('path');
module.exports = {
entry: './src/index.js', // Bundle all assets from this location together
output: {
filename: 'bundle.js', // Output to this file
path: path.resolve( __dirname, 'dist' ) // In this location
},
module: {
rules: [
{
test: /\.(js|jsx|mjs)$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
]
},
devServer: {
contentBase: path.resolve(__dirname, "dist")
}
};
.babelrc:
{
"presets": ["env", "react"]
}
Gets me the following error:
ERROR in ./src/index.js
Module build failed: SyntaxError: Unexpected token (17:12)
15 | render() {
16 | return (
> 17 | <div style={ { textAlign: 'center' } }>
| ^
If I change my webpack.config.js file to this instead it works:
var path = require('path');
module.exports = {
entry: './src/index.js', // Bundle all assets from this location together
output: {
filename: 'bundle.js', // Output to this file
path: path.resolve( __dirname, 'dist' ) // In this location
},
module: {
rules: [
{
test: /\.(js|jsx|mjs)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env', 'react']
}
}
},
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
}
]
},
devServer: {
contentBase: path.resolve(__dirname, "dist")
}
};
From my understanding having the options object or a .babelrc file should do the same thing. But only one of them works.
I don’t have a "babel": {}
block within my package.json so I really don’t see why it seems that the .babelrc file is not recognized.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:36 (7 by maintainers)
Top Results From Across the Web
webpack - .babelrc file is not applied - Stack Overflow
1 Answer 1 · Solution 1: Upgrade babel-loader to 7.1.2+ · Solution 2: Add babelrc: true to your webpack options.
Read more >Config Files - Babel.js
These cases will primarily cause issues for users with a monorepo structure, ... Babel will not find the config file if the working...
Read more >Babel - Storybook
Storybook's webpack config by default sets up Babel for ES6 transpiling. ... part of @storybook/addon-essentials , as this currently causes issues in IE11....
Read more >What is @babel/preset-env and why do I need it? - Jakob Lind
babelrc file and why does it work? It's not a nice feeling to just type something that you read in a tutorial without...
Read more >Babel preset working in .babelrc file but not in Webpack config ...
[Solved]-Babel preset working in .babelrc file but not in Webpack config file-Reactjs ... In your webpack config instead of passing the query option...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have this code in my .babelrc and its working for me.
For more, I have my
and
postcss.config.js
which isI would like to tell you that I am using React with Semantic-ui-react and this configuration is rocking. You can try. If you face any error tell me.
From spelunking the same code, it appears that
options: { babelrc: true }
will also trigger the default behavior. I have no idea why that would not be the default, but hey.