Challenges compiling 'vue-loader' in Webpack caused by '@vue/compiler-sfc' issues

The Challenge

Embarking on the development of a new application, we decided to implement a GULP and Webpack pipeline for compiling SCSS, Vue 3, and Typescript files. However, my recent endeavors have been consumed by a perplexing dilemma. Every time I address one issue, it circles back to a previous problem, creating a frustrating cycle of troubleshooting.

Upon integrating vue-loader, an initial error emerged indicating that vue-template-compiler is an essential dependency. Resolving this missing element resulted in a new complication – a version inconsistency with Vue, necessitating them to be synchronized.

Familiarizing myself with the fact that vue-template-compiler was superseded by @vue/compiler-sfc in version 3, I meticulously uninstalled the former and installed the latter. To my dismay, this action only propelled me back to square one, prompting once more the installation of vue-template-compiler or specification of a compatible compiler through the options.

Diving into various resources concerning compiler configuration within webpack.config proved fruitless, as they merely redirected me to familiar content.

Potential Solutions Attempted

Resolving Vue Template Issue in Vue 3 Optimizing Webpack for Vue 3 Supporting Typescript in Vue 3

Error One Encountered

ERROR in ./Content/Vue/Login.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):
Vue packages version mismatch:
- <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3046455570031e001e0101">[email protected]</a> (<Project Path>\node_modules\vue\index.js)
- <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8deddcd85dccdc5d8c4c9dccd85cbc7c5d8c1c4cddae89a869e86999a">[email protected]</a> (<Project Path>\node_modules\vue-template-compiler\package.json)
This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.

Error Two Encountered

ERROR in ./Content/Vue/Login.vue
Module Error (from ./node_modules/vue-loader/lib/index.js):
[vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.
Error: [vue-loader] vue-template-compiler must be installed as a peer dependency, or a compatible compiler implementation must be passed via options.
    at loadTemplateCompiler (<Project Path>\node_modules\vue-loader\lib\index.js:24:31)
    at Object.module.exports (<Project Path>\node_modules\vue-loader\lib\index.js:69:35)
ERROR in ./Content/Vue/Login.vue
Module build failed (from ./node_modules/vue-loader/lib/index.js):
TypeError: Cannot read property 'parseComponent' of undefined
    at parse (<Project Path>\node_modules\@vue\component-compiler-utils\dist\parse.js:15:23)
    at Object.module.exports (<Project Path>\node_modules\vue-loader\lib\index.js:67:22)
webpack 5.36.2 compiled with 2 errors in 153 ms

Configuration of Webpack Setup

const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");

module.exports = {
    entry: {
        login: "./Content/Vue/Login.vue"
    },
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, "../../wwwroot/Distribution/Scripts")
    },
    mode: "development", 
    plugins: [
        new VueLoaderPlugin()
    ],
    resolve: {
        alias: {
            vue: "@vue/runtime-dom"
        }
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                loader: "ts-loader",
                options: {
                    appendTsSuffixTo: [/\.vue$/],
                },
                exclude: /node_modules/
            },
            {
                test: /\.vue$/,
                loader: "vue-loader"
            }
        ]
    }
}

Package JSON Configuration Overview

{
  "name": "***",
  "version": "1.0.0",
  "description": "***",
  "main": "index.js",
  "license": "UNLICENSED",
  "repository": "***",
  "scripts": {
    "webpack": "webpack --config=Scripts/Webpack/webpack.config.js"
  },
  "devDependencies": {
    "@vue/compiler-sfc": "^3.0.11",
    "css-loader": "^5.2.4",
    "file-loader": "^6.2.0",
    "gulp": "^4.0.2",
    "gulp-clean": "^0.4.0",
    "gulp-clean-css": "^4.3.0",
    "gulp-concat": "^2.6.1",
    "gulp-rename": "^2.0.0",
    "gulp-run": "^1.7.1",
    "gulp-sass": "^4.1.0",
    "gulp-sourcemaps": "^2.6.5",
    "mini-css-extract-plugin": "^1.6.0",
    "ts-loader": "^9.1.1",
    "typescript": "^4.2.4",
    "url-loader": "^4.1.1",
    "vue-loader": "^15.9.6",
    "webpack": "^5.35.0",
    "webpack-cli": "^4.6.0"
  },
  "dependencies": {
    "vue": "^3.0.11",
    "vue-router": "^4.0.6"
  }
}

Answer №1

Right before I was going to post my question, I managed to solve the issue on my own. It turns out that the incorrect version of vue-loader was causing the problem. I'm sharing this solution so that other developers don't have to waste hours searching for it.

While setting up the frontend structure for my application, I encountered a hurdle with Vue versions in NPM – v2.6.12 and v3.0.11. The fix was simple: specify the correct version.

The issue extended to vue-loader as well. Currently, the latest version is v15.9.6, but the next version is v16.2.0. In my code (see the included package.json file), I had specified v15.9.6.

To ensure Vue 3 works smoothly with vue-loader, the installed version should be '16.2.0' or higher.

Edit: 16 February 2022

Now, when you download Vue via NPM, you'll get v3 by default. Dependencies like vue-loader, @vue/compiler-sfc, etc., have been updated to work seamlessly with Vue v3 instead of v2. This update should eliminate the problem discussed in this question.

Answer №2

Try executing this command to potentially resolve the issue: npm install [email protected]

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

`Some Items Missing from Responsive Navigation Menu`

Hey there! I'm currently diving into the world of responsive design and I'm attempting to create a navigation bar that transforms into a menu when viewed on a mobile device or phone. Everything seems to be working fine, except that not all the na ...

Vue component prop values are not properly recognized by Typescript

Below is a Vue component I have created for a generic sidebar that can be used multiple times with different data: <template> <div> <h5>{{ title }}</h5> <div v-for="prop of data" :key="prop.id"> ...

Assigning a session variable through a dropdown selection

Currently, I am working on a custom WordPress theme that involves setting a session variable based on the value selected from a dropdown box. This session variable is then used to determine which container should be loaded. The code snippet below shows whe ...

Inspecting the Nuxt.js application, retrieve the build version using console.log

Currently, my Nuxt site is being hosted on AWS S3 with Cloudfront. Whenever I deploy a new version, I have to invalidate the CloudFront CDN which causes a delay in the deployment process. I want to display the build hash by using console.log(buildHash) wh ...

Ways to ascertain if a view has completed rendering in JavaScript

I am currently building my application using the awesome backbone.js framework. Within my code, I have this layoutView that handles rendering the overall layout and also includes a smaller profile section. The dilemma I'm facing is with the timing o ...

Different ways to resize an image in various sizes without relying on PHP thumb

I have developed an admin panel for managing reservations of charter, yacht and other vehicles. I am looking for a solution to upload only one image per vehicle and resize it in multiple sizes without relying on the phpthumb library due to its slow loadi ...

Verify if the nested JSON object includes a specific key

Currently, I am grappling with a dilemma on how to determine if within a deeply nested JSON object, featuring numerous unknown arrays and properties, lies a specific property that goes by the name "isInvalid". My objective is to identify this property and, ...

Failed PHP response when jQuery was called

I'm working on a project that involves two files: one PHP and one HTML. The HTML file acts as the user interface where users input their queries, while the PHP file handles the processing and events before returning the output back to the HTML file. I ...

Why isn't the customer's name a part of the CFCustomerDetails class?

Currently, I am utilizing the cashfree-pg-sdk-nodejs SDK to integrate Cashfree payment gateway into my application. Upon examining their source code, I noticed that the CFCustomerDetails class does not include the customerName attribute. https://i.stack.i ...

Vue.js versatile form for both adding and editing

As a newcomer to the world of vue.js, I am currently working on expanding some tutorials that I have completed. After struggling with this for three hours now, I must admit that I am feeling quite frustrated. Just to give you a heads up, I am using firebas ...

Unable to pass props to component data using Vue framework

I'm facing an issue with passing props in my component to the same component's data object. For some reason, I'm only receiving null values. Does anyone have any suggestions on how I should approach this problem? It seems like my Vue compone ...

How to Implement Button Disable Feature in jQuery When No Checkboxes Are Selected

I need help troubleshooting an issue with a disabled button when selecting checkboxes. The multicheck functionality works fine, but if I select all items and then deselect one of them, the button disables again. Can someone assist me with this problem? Be ...

Triggering a function in response to a click

I'm encountering an issue with calling a callback inside a click event. Initially, I am attaching the click event to each table row. jQuery(tr).click(function (event) { var that = this; A(event, that, function () { var $gantt_containe ...

Mastering the art of properly connecting Angular HttpPromise

Recently, I encountered an angular Service containing a crucial function: service.getItemByID = function(id) { var hp = $http({method: "GET", url: "service/open/item/id", headers: {"token": $rootScope.user.token}, para ...

Exploring the functionality of CodePen's code editor in relation to developing a 2D shooting game

Recently, I created a straightforward 2D shooter game with all the code neatly organized in a single HTML file: (file_gist). When I tested the game in my chrome browser, everything worked flawlessly according to my intentions. However, upon transferring th ...

"Utilizing jQuery to integrate an Ajax-powered Gauge using Google Visualization API

I need help creating a dynamic dashboard gauge that updates using ajax. The code snippet below shows what I have so far, but I'm struggling with updating the gauge itself. Any advice or suggestions on how to achieve this? google.load('v ...

Issue with conditional comment in IE 8 not functioning as expected

Struggling with changing the SRC attribute of my iFrame specifically for users on IE 8 or older. This is the code I have written: <script> var i_am_old_ie = false; <!--[if lte IE 8]> i_am_old_ie = true; <![endif]--> </script> ...

Guide on fetching data using Index Number in Vue Js from an Api?

Query 1: Is there a method in Vue Js to retrieve data based on Index Number from an API? Q2. I am facing an issue where using {{item.title}} results in an error stating that the title is undefined... Any suggestions for resolving this problem? ...

Developing a sliding menu with AngularJS

Currently, I am developing an AngularJS application. One of the features I am working on involves having a menu at the top of my page that, when an item is selected, will slide down to reveal content specific to that selection in the same area as the menu. ...

What is the best way to manage various versions of JS libraries across different branches?

As a novice developer, I dabble in creating applications for personal use. My go-to tools are the Quasar framework for the front end and Python for the back end. I maintain a git repository where the master branch houses my "production code," but now I am ...