Exploring the capabilities of Vue combined with Typescript and Audio Worklets

I've encountered a challenge with configuring Vue to compile audio worklets. Specifically, I am facing a similar issue to this problem that has already been resolved, but using Typescript instead of JavaScript. My approach was to include the ts-loader before the worklet-loader when processing *.worklet.ts files. However, TypeScript is not generating any output for some reason:

 ERROR  Failed to compile with 1 error                                                                                                                                                     20:37:39
 error  in ./src/window.worklet.ts

Syntax Error: Error: TypeScript emitted no output for D:\(...)\equalizer\src\window.worklet.ts.


 @ ./src/visualizer.ts 44:0-50 45:12-30
 @ ./node_modules/cache-loader/dist/cjs.js??ref--14-0!./node_modules/babel-loader/lib!./node_modules/@vue/cli-plugin-typescript/node_modules/ts-loader??ref--14-2!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/TabVisuals.vue?vue&type=script&lang=ts
 @ ./src/components/TabVisuals.vue?vue&type=script&lang=ts
 @ ./src/components/TabVisuals.vue
 @ ./node_modules/cache-loader/dist/cjs.js??ref--14-0!./node_modules/babel-loader/lib!./node_modules/@vue/cli-plugin-typescript/node_modules/ts-loader??ref--14-2!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/App.vue?vue&type=script&lang=ts
 @ ./src/App.vue?vue&type=script&lang=ts
 @ ./src/App.vue
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://(...):8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js ./src/main.ts

This is my vue.config.js:

module.exports = {
    css: {
        loaderOptions: {
            sass: {},
        },
    },
    configureWebpack: {
        module: {
            rules: [
                {
                    test: /\.worklet\.tsx?$/i,
                    exclude: /node_modules/,
                    use: [
                        {
                            loader: "ts-loader",
                            options: { projectReferences: true },
                        },
                        {
                            loader: "worklet-loader",
                            options: {
                                name: "js/[hash].worklet",
                            },
                        },
                    ],
                },
            ],
        },
    },
};

Currently, TypeScript lacks full support for Audio Worklets. Hence, I have integrated the recommended definitions into my TypeScript project to enable parsing of worklets.

Answer №1

After thoroughly examining the Weboack documentation, I managed to resolve the issue. An important point to note is that loaders are applied in reverse array order. Below is a functional vue.config.js:

module.exports = {
    css: {
        loaderOptions: {
            sass: {},
        },
    },
    configureWebpack: {
        module: {
            rules: [
                {
                    test: /\.worklet\.ts$/i,
                    exclude: /node_modules/,
                    use: [
                        {
                            loader: "worklet-loader",
                            options: {
                                name: "js/[hash].worklet.js",
                            },
                        },
                        {
                            loader: "ts-loader",
                            options: {
                                configFile: "tsconfig.worklet.json",
                            },
                        },
                    ],
                },
            ],
        },
    },
};

tsconfig.worklet.json:

{
    "compilerOptions": {
        "target": "ES2018",
        "module": "esnext",
        "strict": true,
        "importHelpers": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "experimentalDecorators": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "sourceMap": true,
        "baseUrl": ".",
        "types": ["webpack-env"],
        "paths": {
            "@/*": ["src/*"]
        },
        "lib": ["esnext", "scripthost"]
    },
    "include": ["src/**/*.worklet.ts"],
    "exclude": ["node_modules"]
}

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

Exploring ways to conduct a thorough scan of object values, inclusive of nested arrays

My goal is to extract all values from an object. This object also includes arrays, and those arrays contain objects that in turn can have arrays. function iterate(obj) { Object.keys(obj).forEach(key => { console.log(`key: ${key}, value: ${o ...

Accessing properties in Angular/TypeScript: extracting values from a partially extended interface

I am fairly new to Angular/TS and I may not have worded this correctly, but I will do my best to explain. I have defined 2 interfaces where one extends the other as shown below: export interface CustomerModel { firstName: string; lastName: string; ...

Is it possible to refactor the repeated code in Vue custom modifiers across multiple v-models?

I encountered an issue with code quality while using multiple v-model bindings in vue 3. The problem arose when I had to repeatedly write the emit value function, with about 90% of the function code being identical. Is there a way to refactor this code eff ...

How to share data between two different components in Angular 6

I have a component called course-detail that fetches data (referred to as course) from my backend application. I want to pass this data to another component named course-play, which is not directly related to the course-detail component. The goal is to dis ...

It appears that the setup function completes its execution before the onMount function is called in Vue 3

createApp({ setup() { let price = 0 onMounted() { // axios price = axios.response } return { price } } }).mount('#app') HTML <h6 id="app" class="mb-0"> ...

What is the recommended return type in Typescript for a component that returns a Material-UI TableContainer?

My component is generating a Material-UI Table wrapped inside a TableContainer const DataReleaseChart = (): React.FC<?> => { return ( <TableContainer sx={{ display: 'grid', rowGap: 7, }} > ...

I encountered an issue with the laravel-Vue-pagniation where I was unable to navigate to a different page

When using a Table, data is displayed as expected. However, upon clicking on the page number provided by the Laravel Vue pagination, the same page number 1 is shown. The issue arises from the fact that the page number is not being passed into the function ...

Leverage the same JSDoc comment across multiple TypeScript interfaces

If I have the interfaces below: interface Foo { /** * A date string in the format `yyyy-MM-dd` */ archiveDate: string; } interface Bar { /** * A date string in the format `yyyy-MM-dd` */ publishDate: string; } The JSDoc descriptions f ...

Webpack is refusing to compile my code after attempting to import a mongoose model

I've been working on a React blog app that utilizes MongoDB to store posts. However, I encountered an issue where webpack fails to compile when attempting to import a Mongoose model into my NewPost component. Below are the errors I'm facing: W ...

Issue encountered when attempting to develop a countdown timer using Typescript

I am currently working on a countdown timer using Typescript that includes setting an alarm. I have managed to receive input from the time attribute, converted it using .getTime(), subtracted the current .getTime(), and displayed the result in the consol ...

VueJS: Dynamically Change Events in FullCalendar Based on User Input

I have successfully set up fullcalendar in vuejs, displaying events for 3 members. Now I am looking to implement a feature that allows users to show or hide specific users' events with just a click. Although I have experience with jQuery, I am new to ...

The Cordova InAppBrowser plugin has not been properly set up

After running cordova plugin list, I noticed that the InAppBrowser plugin is listed. However, when I try to run my code on an android device, I receive this message in the console via Chrome Remote Debugger: Native: InAppBrowser is not installed or you ar ...

Ways to ascertain whether a user has successfully logged in

Just diving into Angular testing and decided to test out the checkLogin function within my application. import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import {AuthenticationService} from &qu ...

What is the best way to set up a JSON attribute with properly formatted JSON data?

Within this code snippet, the variable some is assigned a JSON string that requires expansion and proper indentation for improved readability. export class MyComponent implements OnInit { some:any = JSON.parse('[{"id":"EN","fill":"blue","classb ...

Is it possible to limit the items in a TypeScript array to only accept shared IDs with items in another array?

I'm creating an object called ColumnAndColumnSettings with an index signature. The goal is to limit the values of columnSettings so that they only allow objects with IDs that are found in columns. type Column = { colId: string, width?: number, s ...

Exploring the use of TypeScript and Webpack to read non-JavaScript files in Node.js

I'm working on a backend NodeJS setup written in TypeScript that is using webpack for compilation. However, I encountered an error when trying to read a text file even though I confirmed that the file source/test.txt is being copied to the build fold ...

Tips for avoiding the push method from replacing my items within an array?

Currently, I am diving into Typescript and VueJS, where I encountered an issue with pushing elements to my array. It seems to constantly override the 'name' property. Let me share the code snippet causing this problem: const itemsSelectedOptions ...

The issue with launching a Node.js server in a production environment

I'm currently facing an issue when trying to start my TypeScript app after transpiling it to JavaScript. Here is my tsconfig: { "compilerOptions": { "module": "NodeNext", "moduleResolution": "NodeNext", "baseUrl": "src", "target": " ...

Using rxjs for exponential backoff strategy

Exploring the Angular 7 documentation, I came across a practical example showcasing the usage of rxjs Observables to implement an exponential backoff strategy for an AJAX request: import { pipe, range, timer, zip } from 'rxjs'; import { ajax } f ...

In Typescript, null values are allowed even when the type is set to be non-nullable

Can someone explain why the code below allows for null in typescript, even though number is specified as the type: TS playground // Not sure why null is accepted here when I've specified number as the type const foo = (): number => 1 || null ...