Implementing the async/await pattern within Vue.js

Implementing the async/await pattern in my new Vue.js project has been a challenge. During my initial attempt, an error was thrown:

<template>
    <div>
        <table>
            <tr>
                <th>Test</th>
            </tr>
            <tr v-for="(value, name) in pickingList">
                <td>{{value}}</td>
            </tr>
        </table>
        s
    </div>
</template>

<script>
    export default {
        name: 'Test',
        data() {
            return {
                pickingList: null,
                pickingZone: '1006'
            }
        },
        async created() {
            await this.getPickingList();
        },
        methods: {
            async getPickingList() {
                this.pickingZone = await this.$http.get("Picking/PickingZoneLists/" + this.pickingZone);
            }
        }
    }
</script>

The error message I received was as follows:

webpack-internal:///./node_modules/vue/dist/vue.esm.js:629 [Vue warn]: Error in created hook: "ReferenceError: regeneratorRuntime is not defined"

found in

---> at src/views/Test.vue at src/containers/TheContainer.vue at src/App.vue warn @ webpack-internal:///./node_modules/vue/dist/vue.esm.js:629 webpack-internal:///./node_modules/vue/dist/vue.esm.js:1896 ReferenceError: regeneratorRuntime is not defined at VueComponent.created (webpack-internal:///./node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/Test.vue?vue&type=script&lang=js&:25) at invokeWithErrorHandling (webpack-internal:///./node_modules/vue/dist/vue.esm.js:1862) at callHook (webpack-internal:///./node_modules/vue/dist/vue.esm.js:4216) at VueComponent.Vue._init (webpack-internal:///./node_modules/vue/dist/vue.esm.js:5001) at new VueComponent (webpack-internal:///./node_modules/vue/dist/vue.esm.js:5147) at createComponentInstanceForVnode (webpack-internal:///./node_modules/vue/dist/vue.esm.js:3289) at init (webpack-internal:///./node_modules/vue/dist/vue.esm.js:3120) at merged (webpack-internal:///./node_modules/vue/dist/vue.esm.js:3307) at createComponent (webpack-internal:///./node_modules/vue/dist/vue.esm.js:5973) at createElm (webpack-internal:///./node_modules/vue/dist/vue.esm.js:5920)

In an attempt to resolve this issue, I came across a solution suggesting the installation of two specific Babel plugins:

  • @babel/polyfill
  • @babel/plugin-transform-regenerator

After installing them using npm and updating my babel.config.js file with the necessary configurations:

module.exports = {
    presets: [
        ['@babel/preset-env']
    ],
    plugins: [
        ['@babel/polyfill'],
        ['@babel/plugin-transform-regenerator']
    ]
}

However, following these changes, the page started crashing immediately, displaying a vague error page filled with SocketExceptions and HttpRequestExceptions:

Failed to proxy the request to http://localhost:8081/mypage, because the request to the proxy target failed. Check that the proxy target server is running and accepting requests to http://localhost:8081/. The underlying exception message was 'Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte.'.Check the InnerException for more details.

I began to question if the chosen Babel plugins were indeed the right approach. If so, what steps can be taken to tackle this problem?

Additionally, I stumbled upon a related post here, which references the need for a webpack config file. However, here are the contents of my vue.config.js:

module.exports = {
  lintOnSave: false,
  runtimeCompiler: true,
  configureWebpack: {
    //Necessary to run npm link https://webpack.js.org/configuration/resolve/#resolve-symlinks
    resolve: {
       symlinks: false
    }
  }
}

Finally, included below is my package.json for reference:

{
  "name": "@coreui/coreui-free-vue-admin-template",
  "version": "3.0.0-beta.3",
  ...
}

Answer №1

After conducting some research, I came across a recent article on Medium discussing this topic. The use of @babel/polyfill is now deprecated. Instead, you will need to install @babel/runtime and @babel/plugin-transform-runtime, followed by making adjustments to your babel.config.js file:

npm i -D @babel/plugin-transform-runtime
npm i @babel/runtime
{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-react"
  ],
  "plugins": [
    [
      "@babel/plugin-transform-runtime",
      {
        // "absoluteRuntime": false,
        "corejs": false,
        // "helpers": true,
        "regenerator": true,
        // "useESModules": false
      }
    ]
  ]
}

You can find more details in the source article: https://medium.com/@kishan020696/react-16-with-webpack-4-and-babel-7-part-2-edb34d78f695

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Displaying the focus icon on the active tab using Angular Material

I am currently utilizing Angular material to dynamically generate tabs in my HTML code. I'm trying to display a drop arrow icon on the active or selected tabs, but I am facing some challenges with the implementation. Below is the code snippet I have ...

Master the art of string slicing in JavaScript with these simple steps

I am attempting to utilize the slice function to remove the first three characters of a string within a JSON object. $(document).ready(function() { $.ajaxSetup({ cache: false }); setInterval(function() { $.getJSON("IOCounter.html", functio ...

What steps should I take to protect a Vue application running on Docker using Nginx?

After creating a Vue app following the cookbook, I successfully created a docker image that runs without any issues. However, I encountered a problem with using Vue Qrcode Reader. The Troubleshooting guide recommends securing the app through HTTPS in order ...

Error encountered while building Tauri app - windres execution failed during compilation

Attempting to create a Tauri/Vuejs desktop application with Nestjs as the sidecar. Upon running the build command npm run tauri build , an error is encountered: Error: failed to execute custom build command for `app v0.1.0 (E:\ItharApp\ithar_fron ...

Error with review score in material-ui for react.js

There is an issue with my code where the ratings from different sets are not behaving independently. When a rating in one set is clicked, only the first set of ratings changes, suggesting that there is a connection between all the sets. https://i.sstatic. ...

What is the best way to transform this JSON data into an HTML table using JavaScript?

I am looking to dynamically create an HTML table based on changing json data. I want the table to maintain consistent alignment and width, similar to the example shown here. How can I convert the incoming json data into a well-structured HTML table? [ ...

Form duplicates messages sent

I have made some adjustments to a free form, and it seems to be functioning properly. However, I have encountered an issue where the email is being sent twice and the message is written twice after completion. I attempted to replace the button and input ...

Having trouble loading texture locally in THREE.js?

Here's the scenario: I have a local file where I attempt to load a texture using the following code: var texture = THREE.ImageUtils.loadTexture( 'image.jpg' ); var cubeGeo = new THREE.CubeGeometry( 50, 50, 50 ); var cubeMat = new THREE.Mesh ...

What steps should I take to solve this wheel-related issue in my Vue 3 application?

I have been developing a Single Page Application (SPA) using Vue 3, TypeScript, and The Movie Database (TMDB). Currently, I am tackling the implementation of a search feature and I've encountered a bug. The "search-box" component is located in src&b ...

audio enhancement in a web-based game

I'm having trouble getting a sound effect to play consistently in my game whenever there is a hit. Sometimes the sound plays, other times it does not! Here is the code I am using: <script> var hitSound = new Audio(); function playEffectSound ...

Addressing Browser Incompatibility in React.js Event Handling

I've recently embarked on my journey to learn React.js by delving into various tutorials and documentation. However, I'm encountering a peculiar issue specifically in Google Chrome: https://i.sstatic.net/qODiP.png Interestingly, in Firefox, it ...

"Sticky Top Button That Stays in Place When Scrolling | Innovative CSS & jQuery

I've been inspired by the "Proceed to checkout" button on amazon.com and I want to recreate it. However, I'm facing a challenge as their website is not responsive and I can't find a way to view a device user agent in Chrome. To see what I&ap ...

What is the best way to eliminate the final character from a series of repeated Xs and following strings

Data consists of [one][two][three]. I want to exclude the last set of brackets and have a result like [one][two]. How can this be achieved using jQuery? ...

Achieving a child div to occupy the entire available space when the parent is specified as `mx-auto` can be accomplished using Vue and Tailwind CSS

Sorry if this seems like a basic question, I'm still getting the hang of Vue and tailwind. In my parent template, it looks like this: <template> <div class="mx-auto mt-4 max-w-3xl"> <slot></slot> </div> ...

I am having trouble specifying a class within an SVG using D3.js

I have been facing a strange issue with my script. When I try to execute the following code: var key="#US" d3.select(key).style("fill", "red"); it seems like it's not working for me. Interestingly, when I run the same co ...

Choosing items while using the Orthographic camera in Three Js

Currently, I am working on an isometric level and facing issues while trying to select objects within the level. I have tried various solutions from Stackoverflow, such as this one Orthographic camera and selecting objects with raycast. However, none of t ...

Updating the content of a div when the mouse hovers over it

Looking for some help here - I have a few divs with paragraphs of text inside. My goal is to change the text in each div when it's being hovered over. I know this can be done using JavaScript (jquery perhaps?), but my coding skills are pretty basic. A ...

What is the best way to provide two unique versions of websites using one domain?

I've embarked on a project that requires a complete rewrite. Instead of opting for a big bang release, we've decided to utilize the Strangler Pattern as outlined here. The current application (details below) will continue to run unchanged under ...

How to effectively expose a node controller function for testing in Mocha

Below is the code for my foo-controller.js. module.exports = function(params) { var router = require('express').Router(); var db = params.db var controller = {}; controller.getFoo = function (req, res) { // logic to ret ...

Submit button on Ajax form causes automatic page refresh

After adding a simple Ajax form to my WordPress website, I encountered an issue where the validation works fine, but instead of sending the email, the form refreshes after submitting. Here is the code snippet: <script type="text/javascript"> jQ ...