Skip to content
Advertisement

Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it

I am using axios to access the backend when a user registers, it takes their name, email, and password and dispatches REGISTER_SUCCESS when they are successful. When a user fails to register, it dispatches. for dispatch am using redux thunk as middleware so i can write dispatch in arrow function REGISTER_FAILURE, but instead gets the error below. This is stated in the webpack documentation.

topLevelAwait: Support the Top Level Await Stage 3 proposal, it makes the module an async module when await is used on the top-level. And it is enabled by default when experiments.futureDefaults is set to true.

But I don’t know how to implement this code. I have tried react-scripts webpack.config.js file, but I get another error. Can you please help?

ERROR IN CONSOLE

JavaScript

AUTH.JS FILE

JavaScript

Advertisement

Answer

The problem was with the axios because we don’t need a config object for axios as the default headers in axios are already Content-Type: application/json also axios stringifies and parses JSON for you, so no need for JSON.stringify or JSON.parse

there is no need to write config file default headers in axios are already Content-Type: application/json

JavaScript

change my code to this here formdata contains email,name and password

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement