[Solved] React async/await API call failed. ReferenceError: regeneratorRuntime is not defined Babel 6

ReferenceError: regeneratorRuntime is not defined

Problem

I’m trying to use async, await APIs with Babel 6, and I’m getting a ‘regeneratorRuntime is not defined’ error. Here below I have added configuration files.

How we can do it without .babelrc (just using webpack config file)?.

Solution

This error is caused when async/await functions are used without the proper Babel plugins.  To install @babel/plugin-transform-runtime by typing in the command line,

npm install --save-dev @babel/plugin-transform-runtime

Then Add the plugin to pakage.json file in plugins array.

So the final changes of the package.json and webpack.config.dev.js file would be,

package.json file

Note: We assume that the installed all below-highlighted packages related to babel configurations, otherwise do copy and replace the above configuration code to the package.json file and do run this command npm i again in the command window.

webpack.config.dev.js file

Shivaraju M

Over 3+ years experience in IT industry, good knowledge in . Net-based Web applications, windows applications, web services, and SPAs. I have played multiple roles related to technical delivery in multiple domains while working on over 10+ technologies. I am currently focused on continuous improvement and agile project management.

Post a Comment

Previous Post Next Post