TypeScript is unable to recognize files with the extension *.vue

Can someone assist me with an issue I'm facing in Vue where it's not detecting my Single File Components?

Error message:

ERROR in ./src/App.vue (./node_modules/ts-loader!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue)
Module build failed: Error: Could not find file: 'F:\Projects\core\client\src\App.vue'.
    at getValidSourceFile (F:\Projects\core\client\node_modules\typescript\lib\typescript.js:107554:23)
    at Object.getEmitOutput (F:\Projects\core\client\node_modules\typescript\lib\typescript.js:108052:30)
    at Object.getEmitOutput (F:\Projects\core\client\node_modules\ts-loader\dist\instances.js:187:41)
    at getEmit (F:\Projects\core\client\node_modules\ts-loader\dist\index.js:196:37)
    at successLoader (F:\Projects\core\client\node_modules\ts-loader\dist\index.js:34:11)
    at Object.loader (F:\Projects\core\client\node_modules\ts-loader\dist\index.js:21:12)
 @ ./src/App.vue 7:0-97 7:0-97 8:0-110 21:2-16
 @ ./src/index.ts
 @ multi (webpack)-dev-server/client?http://localhost:9000 webpack/hot/dev-server ./src/index.ts

I have also added the vue-shims.d.ts file as suggested by other posts.

declare module "*.vue" {
    import Vue from "vue"
    export default Vue
}

tsconfig.json

{
  "compilerOptions": {
    // this aligns with Vue's browser support
    "target": "es5",
    // this enables stricter inference for data properties on `this`
    "strict": true,
    // if using webpack 2+ or rollup, to leverage tree shaking:
    "module": "es2015",
    "moduleResolution": "node",
    "lib": [ "es2015", "es2017", "es6", "dom", "es2015.iterable" ],
    "noImplicitAny": true,
    "strictNullChecks": true,
    "allowSyntheticDefaultImports": true
  }
}

If I change the imports to ./App.vue.d then it works, but obviously importing a typings file doesn't give you the actual contents of the file you need.

App.vue

<template>
    <div class="height-100 width-100">
        <div class="app-container height-100 width-100">
            <router-view></router-view>
        </div>
        <offline-notice></offline-notice>
    </div>
</template>

<script lang="ts">
    import Vue from "vue"

    export default Vue.extend({
        components: {
            "offline-notice": () => import("../src/components/common/OfflineNotice.vue")
        }
    })
</script>

<style lang="sass">
    @import "assets/stylesheets/variables"
    @import "assets/stylesheets/base"
    @import "assets/stylesheets/helpers"
    @import "../node_modules/izitoast/dist/css/iziToast.min.css"
    @import "assets/stylesheets/components/notifications"
</style>

index.ts

import Vue from "vue"
import VueRouter from "vue-router"
import "element-ui/lib/theme-chalk/index.css"
import "./assets/stylesheets/vendor/ionicons.min.scss"
import "babel-polyfill"

import { store } from "./store"
import { routes } from "./routes/routes-setup"
import { setupSelectedElementUIComponents } from "../config/element-ui-helper"

import App from "./App.vue"

Vue.use(VueRouter)

setupSelectedElementUIComponents(Vue)

const router = new VueRouter({
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        }
        if (to.hash) {
            return {selector: to.hash}
        }
    }
})

// noinspection TsLint
new Vue({
    el: "#app",
    router,
    store,
    render: h => h(App),
})

My base webpack config:

const ExtractTextPlugin = require("extract-text-webpack-plugin")
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")

module.exports = {
    entry: {
        main: "./src/index.ts",
        vendor: [
            "string-format",
            "element-ui",
            "izitoast",
            "vue-swal",
            "vue",
            "axios",
            "croppie",
            "vue-router",
            "vuex",
            "vuex-persistedstate",
        ]
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                exclude: /node_modules|vue\/src/,
                loader: "ts-loader",
                options: {
                    appendTsSuffixTo: [/\.vue$/]
                }
            },
            {
                test: /\.vue$/,
                loader: "vue-loader",
                options: {
                    esModule: true
                }
            },
            {
                test: /\.tsx?$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    appendTsSuffixTo: [/\.vue$/],
                }
            },
            {
                test: /\.js$/,
                loader: "babel-loader",
                exclude: /node_modules/
            },
            {
                test: /\.(png|jpg|gif|svg)$/,
                loader: "file",
                options: {
                    name: "[name].[ext]?[hash]"
                }
            },
            {
                test: /\.css$/,
                use: ["style-loader", "css-loader"]
            },
            {
                test: /\.(scss|sass)$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ["css-loader", "sass-loader"]
                })
            },
            {
                // Match woff2 in addition to patterns like .woff?v=1.1.1.
                test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
                loader: "url-loader",
                options: {
                    // Limit at 50k. Above that it emits separate files
                    limit: 50000,

                    // url-loader sets mimetype if it"s passed.
                    // Without this it derives it from the file extension
                    mimetype: "application/font-woff",

                    // Output below fonts directory
                    name: "./fonts/[name].[ext]"
                }
            },
            {
                test: /\.(ttf|eot|woff|woff2)$/,
                loader: "file-loader",
                options: {
                    name: "fonts/[name].[ext]"
                }
            },
        ]
    },
    resolve: {
        alias: {
            'vue$': 'vue/dist/vue.esm.js'
        },
        extensions: [".js", ".vue", ".json", ".scss", ".sass", ".ts"]
    },
    optimization: {
        splitChunks: {
            chunks: "async",
            minChunks: 1,
            maxAsyncRequests: 5,
            maxInitialRequests: 3,
            name: true,
            cacheGroups: {
                default: {
                    minChunks: 2,
                    priority: -20,
                    reuseExistingChunk: true
                },
                vendors: {
                    test: /[\\/]node_modules[\\/]/,
                    priority: -10
                }
            }
        }
    },
    plugins: [
        new ExtractTextPlugin({
            filename: "[name].[hash].css"
        }),
        new ForkTsCheckerWebpackPlugin({
            vue: true,
        })
    ]
}

Answer №1

This solution ended up being successful for me.

After updating from "vue-loader": "^14.2.2", to "vue-loader": "^15.2.4",, I also included the VueLoaderPlugin plugin in my webpack setup (Webpack 4).

webpack.common.js

const {VueLoaderPlugin} = require('vue-loader')
...
plugins: [
    new ExtractTextPlugin({
        filename: "[name].[hash].css"
    }),
    // new ForkTsCheckerWebpackPlugin({
    //     vue: true,
    // }),
    new VueLoaderPlugin()
]

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

Utilizing Bootstrap to allow for seamless text wrapping around a text input field

I am trying to implement a "fill-in-the-blank" feature using Bootstrap, where users need to enter a missing word to complete a sentence. Is there a way to align the text input horizontally and have the rest of the sentence wrap around it? This is my curr ...

An easy guide to dynamically assigning a property using jQuery

I am currently utilizing the toastr plugin and I would like to dynamically set the options using a JSON object that is retrieved from an AJAX call. I am encountering some difficulties in setting the options property and value programmatically. Below is a s ...

Prevent automatic scrolling to the top of the page after submitting a form. Remain at the current position on the

After submitting a form, I want to prevent the page from automatically scrolling back up. How can I keep the same position on the page after form submission? <script type="text/javascript"> var frm = $('#form'); frm.submit(function ...

Avoiding memory leaks when using three.js with a large number of shapes

My code is devouring memory at an alarming rate and ultimately crashing. After some investigation, I've determined that the issue seems to be related to the torus generation/removal portion of the code. Despite efforts to manage the scene array and t ...

What is the reason behind this code's ability to detect vowels as well as other

I'm currently working on debugging a specific portion of code for my class. I'm having trouble understanding why this JavaScript code is counting all letters instead of just vowels. var text, i, sLength, myChar; var count; var text = prompt("Ple ...

Is it possible to directly update the label text in AngularJS from the view itself?

I found the following code snippet in my HTML <span ng-class="newProvider ? 'newProvider' : ''" class="help-block"> {{ 'new-product.provider.helper' | locate }} </span> Whenever newProvider is se ...

Steps to dynamically update a dropdown list with the value of another field

I am currently working on a dropdown list featuring all countries. Here is the code snippet: <select id="Country" onchange="country();"> <option id="3">Japan</option> <option id="4">Canada</option> <option id="5"> ...

The functionality of Javascript Regular Expressions is not performing as expected

I am currently facing an issue with email validation in JavaScript as it doesn't seem to be working properly. PROBLEM: Even when entering a VALID email address, the alert still shows that my address is faulty... What could I possibly be missing he ...

Track when a user modifies a <select> dropdown list generated using the Jquery method ".html()"

Is it possible to detect a change in the value of a select list when that select list has been added using either the .html(htmlString) or .append(content[,content]) jQuery function? HTML CODE: <ul class="htmlClass"> <!-- Populated via JS --& ...

The button click event fails to trigger after entering text into an input field

I created a basic calculator. Users can input a value in the designated field and then click on the '+' button. The cursor stays in the input field, allowing users to immediately enter a new value after clicking the '+'. The mouse poi ...

How can a HTML element be clicked in JQuery to copy it into a text area?

Is it possible to select text from a list and insert it into a text box by clicking on it? I have developed a JSON API that retrieves a list of individuals from the database. Following this, there is a form with a text field that displays the list of peopl ...

What is the proper method for utilizing a conditional header in an rtk query?

How can I implement conditional header authentication using rtk query? I need to pass headers for all requests except refresh token, where headers should be empty. Is it possible to achieve this by setting a condition or using two separate fetchBaseQuery ...

Node.js - Headers cannot be sent again once they have been sent

I came across a similar issue to mine at this link. I suspect that the error is occurring due to how my .end() calls are configured. Let's take a look at the code in question: app.get('/anihome',function(req,res){ var context = {}; functi ...

Iterate over each item in the select and include a blank option if either of the elements is missing

Having trouble with 2 drop down menus, select1 and select2. I select item1 from select1 and then click the OK button. But when the selected index is 0 (first option), I want to loop through the items of both drop downs. If the elements at the same index ( ...

Adjust the class of a div element located close to its ancestor using JavaScript

I'm trying to change the class of the element #sidePanel from .compact to .expanded dynamically in this code snippet: <div id="sidePanel" class="compact"></div> <div id="topbar"> <div id="buttonContainer"> <div ...

What is the best way to adjust a CSS width using the output from a JavaScript function?

I am facing a challenge with a GridView within a div wrapper. The row headers along the left side need to always be visible. So far, this setup is working fine. However, I need the wrapper to have a variable width to adjust to the browser size. Although I ...

The craft of masonry is known for its creation of intentional gaps

I've gone through all the posts related to this issue, but none of the suggested solutions seem to work for me. Here is a visual representation of my grid: If you want to see the code and play around with it, check out this jsfiddle. Below is the HT ...

How to upload multiple files using AngularJS and Laravel without using a form tag

I am seeking a solution to upload multiple files without using the form tag, utilizing AngularJS with Laravel 5.2. The code snippet below is functional for uploading a single file but fails when attempting to upload multiple files. Here is the HTML Code: ...

Utilize JavaScript to Forward Subdomain to Main Domain

Utilizing Apache envvars, I have created the MYDOMAIN and MYSUBDOMAIN variables to define 'mydomain.com' and 'sub.mydomain.com'. These variables are then used in the Apache sites-available conf files for website deployment. The 'su ...

Rect cannot be resized using mouse events

I am currently working on resizing the rectangle inside the SVG using mouse events. To achieve this, I have created another circle shape at the right bottom edge of the rectangle and implemented resize events on that shape. However, I'm facing an issu ...