The regeneratorRuntime variable is undefined when running TypeScript code in a web environment

I recently experimented with Vue.js + TypeScript + Parcel, exploring the usage of async/await in my index.ts file.

index.html

<html>
...
<body>
  <script src="index.ts"></script>
</body>
</html>

index.ts

console.log('I am not visible')
(async () => {
  console.log('This doesn't get executed either.')
})()

After running parcel index.html and accessing http://localhost:1234/, an error is displayed in the console: regeneratorRuntime is not defined

index.a4a28941.js:110 Uncaught ReferenceError: regeneratorRuntime is not defined
    at index.a4a28941.js:110
    at Object.parcelRequire.306 (index.ts:3)
    at newRequire (index.a4a28941.js:48)
    at parcelRequire.306 (index.a4a28941.js:80)
    at index.a4a28941.js:106

It seems like the async syntax requires a polyfill to work correctly?

Below is my configuration in tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "jsx": "preserve",
    "module": "esnext",
    "moduleResolution": "node",
    "noImplicitReturns": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext",
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "esnext.array", "dom", "dom.iterable", "scripthost", "es2015.generator"]
  },
  "parcelTsPluginOptions": {
    // If true type-checking is disabled
    "transpileOnly": false
  },
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
  "exclude": ["node_modules"]
}

Answer №1

To tackle the issue, I decided to specify the target as "es5" in the tsconfig.json configuration file:

{
  "compilerOptions": {
    "target": "es5"
  }
}

However, it appears that parcel always defaults to using babel for JavaScript transformation, leading to conflicts with the typescript compiler (refer to this discussion: https://github.com/parcel-bundler/parcel/issues/954 and here: https://github.com/parcel-bundler/parcel/issues/871). Some developers resolved this matter by including babel-polifill in their projects, but this may not be ideal if you solely intend to utilize the typescript compiler without involving babel in the transformation process.

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

Include type declarations for property values that resemble arrays in a generic object

Imagine you have a function that: receives an object with multiple properties and a property name; checks if the property holds an array; if it does, performs an action (such as printing the values it contains) Here's an illustration: function pro ...

What is the correct way to close an ngx-contextmenu in an Angular application?

In my angular project, I implemented an ngx-contextmenu. Within one of my components, the template includes the following code: <div... [contextMenu]="basicMenu"> <context-menu>..... </div> After some time, the component with the conte ...

Encountering an issue while trying to utilize the firestorePlugin from vuefire in Vuejs 3 createApp. The problem is that I am receiving an Uncaught TypeError: Cannot set property '$

I recently encountered an issue in my Vue.js 3 app with the following code snippet in my main.js file: import { createApp } from "vue"; import App from "./App.vue"; import { firestorePlugin } from "vuefire"; const app = creat ...

The <v-select> component in VueJS fails to bind properly during a post operation

Currently, I am in the process of developing an asp.net mvc application that utilizes VueJS on the front end. While working with a variety of forms, I have encountered an issue where text fields function properly when submitting the form; however, this is ...

Having an excess of 32 individual byte values

My current project involves developing a permission system using bitwise operators. A question came up regarding the limitation of having only 32 permissions in place: enum permissions { none = 0, Founder = 1 << 0, SeeAdmins = 1 << ...

Is the type narrowed by type guards only when true is returned?

It was my understanding that a type guard handling multiple types instanceOfA(arg: A | B | C): arg is A, would narrow the type to either A (if the guard returns true) or B | C (if it returns false) However, in the case of instanceOfB below, when returning ...

Vue no longer updates when the selected option is changed

Currently, I am working on an app for a class project and have encountered a problem involving fetching the value of a user-selected option instead of the default one. Below is the select element I am utilizing: <select v-model="selectedType" ...

What are the best ways to engage with the Mixcloud Widget?

I have a component with a mixcloud embed code, which looks like this: <template> <div> <iframe id="widget" width="100%" height="60" :src="iframe.src" frameborder="0" v-show="iframe.loaded"></iframe> </div> </templ ...

Having trouble with Laravel Vue.js mixins not receiving function responses?

I'm currently working with Laravel 5.8 and Vue.js. I've created a function for handling post/get requests in a more generalized way. However, I'm facing an issue where I am not receiving the expected response from the mixins function. Below ...

How to invoke a method in a nested Angular 2 component

Previous solutions to my issue are outdated. I have a header component import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; import { Observable } from 'rxjs/Observable'; ...

Incorporating reactive form validation for an Angular application with the use of the <input type="file"> input field

I am in the process of developing a component that includes a file picker for uploading files to our CDN. I am working on integrating a reactive form into this component to validate the image input, allowing me to verify against file name and extension amo ...

Troubleshooting clipboard issues during the deployment of a Vue.js application on an Ubuntu server

Trying to deploy my vuejs app on an EC2 instance with Ubuntu 16.04 has been a bit challenging. When attempting to run the serve command like sudo serve -s dist, I encountered the following error: ERROR: Cannot copy to clipboard: Command failed: xsel --clip ...

Search through an array of objects and assign a new value

I am facing a challenge with an array of objects structured as shown below: [ { "e_id": "1", "total": 0 }, { "e_id": "3", "total": 0 } ] My objecti ...

Unable to retrieve the specific value associated with a key from JSON data

I am attempting to retrieve the value of "id" from a JSON response I received after making a POST request. { "callId": "87e90efd-eefb-456a-b77e-9cce2ed6e837", "commandId": "NONE", "content": [ { "scenarioId": "SCENARIO-1", "Channel": " ...

Transforming classes into functional components with ApexCharts

I am facing a problem with inserting chart.type for ApexCharts. I have tried inserting type: line but it is not working. Can someone please advise me on how to define the chart type or if there is another way to accomplish this? import React, { useStat ...

Leveraging Environment Variables in Vue.js

I've been diving into the official documentation, but haven't come across any information regarding environment variables. While there are community projects that offer support for this feature, they seem a bit excessive for my needs. I'm cu ...

Tips for putting distance between the digits in a number

Is there a way in Vue to format an input field that displays "10000" as "10 000" when typed by the user? ...

Arranging Angular Cards alphabetically by First Name and Last Name

I am working with a set of 6 cards that contain basic user information such as first name, last name, and email. On the Users Details Page, I need to implement a dropdown menu with two sorting options: one for sorting by first name and another for sorting ...

Tips for injecting a service into a class (not a component)

Can you inject a service into a class that is not a component? Consider the following scenario: Myservice import {Injectable} from '@angular/core'; @Injectable() export class myService { dosomething() { // implementation } } MyClass im ...

Send properties depending on a condition housed within a computed property

I am facing an issue with a simple test in the computed() property of Nuxt 3. const test = computed(() => { if (process.client) { console.log('Did work. Is mobile?', window.innerWidth < 768) return window.innerWidth < 768 } e ...