I am running a React project using npm. After hours of research and experimenting, everywhere says I have to add the following code to my ".babelrc" file, which I do not have in my directory and cannot create:
{
"plugins": [
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
But this leads to the following error when I run the code:
ERROR in ./src/components/NavBar/Menu.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/ymoondhra/Desktop/yt-web/src/components/NavBar/Menu.js:
Support for the experimental syntax 'classProperties' isn't currently enabled
(20:10):
18 | }
19 |
> 20 | fast = () => {
| ^
21 | this.speed = 100;
22 | }
23 |
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins'
section of your Babel config to enable transformation.
Found the solution to my question after 3 hours: –create a file called "babel.config.js" in the root directory. –put this in the file. –rerun the program (i.e. npm start).
module.exports = {
presets: [ "@babel/preset-env", "@babel/preset-react" ],
plugins: [ "@babel/plugin-transform-arrow-functions", "@babel/plugin-proposal- class-properties" ]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With