Encountering an error while running `npm run watch` with Laravel, Vue.js, and Typescript

Here's a brief overview of my setup: laravel 8 typescript vuejs

tsconfig.js

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "noImplicitAny": false,
        "sourceMap": false
    },
    "include": [
        "resources/js/**/*",
    ]
}

webpack.mix.js

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .js('resources/js/pages/user/configuration/configuration.js', 'public/js/pages/user/configuration')
    .postCss('resources/css/app.css', 'public/css')
    .postCss('node_modules/animate.css/animate.min.css', 'public/css')
    .sass('resources/sass/toolbox.scss', 'public/css')
    .vue()
    .webpackConfig({
        module: {
            rules: [
                {
                    test: /\.tsx?$/,
                    loader: 'ts-loader',
                    options: { appendTsSuffixTo: [/\.vue$/] },
                    exclude: /node_modules/,
                }
            ]
        },
        resolve: {
            extensions: ["*", ".js", ".jsx", ".vue", ".ts", ".tsx"]
        }
    });

ConfigurationPage.vue

<template>
    <div class="col col-12 col-xl-6 d-flex tb-m-b-25">
        {{ greeting }}
    </div>
</template>

<script lang="ts">

import { ref } from 'vue'

export default {
    setup() {
        const greeting= ref('hello');

        return {
            greeting
        }
    }
}
</script>

<style></style>

DevDependencies in my package.json:


"devDependencies": {
    "@vue/compiler-sfc": "^3.0.11",
    "axios": "^0.21.1",
    "cross-env": "^7.0",
    ...
},

file/folder structure

resources
 | js
 | | pages
 | | | user
 | | | | configuration
 | | | | | - configuration.js
 | | | | | - ConfigurationPage.vue
 | - app.js
 | - init.ts

The init.ts file is empty. If I don't have at least one .ts file in my resources folder, the ts-loader throws an exception saying it can't find something to compile. It's common practice to use an empty TypeScript file for this purpose.

The Problem

Every time I make a change in ConfigurationPage.vue, I encounter this exception while running npm run watch-poll:

✖ Mix
  Compiled with some errors in 510.02ms
ERROR in /var/www/resources/js/init.ts
2:7-13
[tsl] ERROR in /var/www/resources/js/init.ts(2,8)
      TS2339: Property '__file' does not exist on type '{}'.
webpack compiled with 1 error

I don't understand it, the init.ts file is empty. This doesn't make sense to me.

Answer №1

By switching from the app.js file to app.ts as the entry-point, the problem was successfully resolved.

Furthermore, in the webpack.mix.js file,

replace .vue() with .vue({ version: 3 })

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

Guide on specifying the return type for Rx.Observable.fromPromise() in TypeScript

My current problem involves a function that returns an Rx.Observable created from a promise. Here is the code snippet: var data$ = fetchData(); fetchData() { return Rx.Observable.fromPromise(fetch("someUrl")); } When I hover over the variable data$ i ...

What are the steps to effortlessly install Laravel using Composer on a live server, ensuring a smooth installation process?

I'm having trouble installing Laravel on my cPanel using the command php composer.phar. The installation keeps failing and shows the following error message: To enable extensions, make sure they are enabled in your .ini files: -/opt/alt/php56/et ...

What is the best way to handle .jsx files in my library bundling process with Rollup?

Currently, I am in the process of developing a component library using storybook and rollup. Here is the configuration file rollup.config.mjs /* eslint-disable import/no-extraneous-dependencies */ import peerDepsExternal from 'rollup-plugin-peer-deps- ...

Enhancing performance with React.memo and TypeScript

I am currently developing a react native application. I am using the Item component within a flatlist to display data, however, I encountered an error in the editor regarding the second parameter of React.memo: The error message reads: 'Type 'bo ...

What is the method to display the Vue.js component's identifier?

Here is a link to an official document: https://v2.vuejs.org/v2/guide/list.html#v-for-with-a-Component Below is a demonstration of a simple todo list: Vue.component('todo-item', { template: '\ <li>\ {{ titl ...

methods for determining the child type of an interface in TypeScript

I am currently working on implementing an event bus and have organized all event names and parameters in one interface. Here is how it looks: interface A { a: { x: number y: number } b: { name: string } } function on<T exte ...

Error in VUE when attempting to splice the final element

This component is a simplified version of a larger component I'm currently working on. Can you help me solve the mystery - why am I encountering an error when trying to delete the last item from the list? The error only occurs when deleting the last ...

Ways to transfer information from a function within one element to another element

I have two components: one that logs the indexes of a carousel and I need to pass these indexes into the second component. First Component <template> <div class="container container--white"> <Header /> <carousel-3d @a ...

What could be the reason behind the validation error occurring in this Laravel 8 and Vue 3 application?

Currently, I am developing a registration form with a Laravel 8 API and integrating it with a Vue 3 front-end. In the AuthController, I have implemented the following code snippet for user registration: ... On the front-end side, my setup looks like this ...

The date in a nodejs application appears to be shifted by one day

Despite similar questions being asked before here, the solutions provided did not resolve my issue. Here is the scenario I am dealing with: https://i.sstatic.net/H9rcO.png Upon clicking save, I collect data from certain fields to generate a date using th ...

Listening for Angular 2 router events

How can I detect state changes in Angular 2 router? In Angular 1.x, I used the following event: $rootScope.$on('$stateChangeStart', function(event,toState,toParams,fromState,fromParams, options){ ... }) In Angular 2, using the window.addEv ...

What is the reason behind tsc (Typescript Compiler) disregarding RxJS imports?

I have successfully set up my Angular2 project using JSPM and SystemJS. I am attempting to import RxJS and a few operators in my boot.ts file, but for some reason, my import is not being transpiled into the final boot.js output. // boot.ts import {Observa ...

The process of retrieving an item from an HTML node using Vue.js

My scenario involves a Vue app with the following data: data: function() { return { items: [ {id: 1, text: 'one', other_data: {}}, {id: 2, text: 'two', other_data: {}}, {id: 3, text: &apo ...

What could be causing the inner array typescript to be inaccessible in an Angular 5 application?

Below are the JSON definitions that I am working with: export class Company { name: string; trips : Trip[] = []; } export class Trip{ id: number; name: string; } Within the component, there is a method that contains the ...

How can I utilize a callback in TypeScript when working with interfaces?

Can someone guide me on how to implement an interface in typescript with callback function? interface LoginCallback{ Error: boolean, UserInfo: { Id: string, OrganizationId: string } } interface IntegrationInterface { Ini ...

Angular 4: Leveraging a directive as a universal constant

I am looking to develop a directive that allows me to utilize a template variable in order to access a global variable, much like $rootScope in Angular.JS. The goal is to avoid having to inject a service into every component where I need access to the vari ...

TypeScript and Angular: Error Encountered when Trying to Combine Two Arrays

I'm attempting to combine two arrays of the same type that are nested within a "parent" array. The end goal is to flatten the structure. Below is the code I have been using: ngOnInit() { this.Logs.getAllLogs() .subscribe(logs => { ...

Employ a type as a function in Typescript programming

Looking for a way to convert an ID into an object using a specific type. The type accepts personId as a string parameter and returns either a Person or undefined. export type FindPerson = (personId: string) => Person | undefined; I have multiple person ...

Obtaining the selected value of <mat-radio-group> in a typescript file when the SAVE button is clicked

I am facing a situation where I have radio buttons in my HTML code. The radio button options are as follows: <mat-radio-group aria-label="Availability for joining" formControlName="availabilityGroup"> <mat-radio-butt ...

Different ways to turn off the phpMyAdmin login page?

I'm currently facing an issue with my live website. Every time I type in this URL: www.mydomain.com/phpmyadmin The phpMyAdmin login page pops up. I'm puzzled as to why this happens, since the local version of the website doesn't show php ...