Issue with vue-template-compiler in Vue.js 3 webpack configuration

I am currently working on integrating vuejs 3 into a project that already utilizes webpack. I have been looking into using vue-loader as part of this process.

After consulting the official documentation, I came across the following information:

Every new release of Vue comes with an accompanying version of vue-template-compiler. It is crucial to ensure that the compiler's version matches the base Vue package in order for vue-loader to generate code that is compatible with the runtime. Therefore, whenever you update Vue in your project, it is necessary to also update vue-template-compiler to maintain synchronization.

However, when attempting to compile, I encountered the following error message:

Vue packages version mismatch:

- [email protected] (/home/alejo/playground/parquesFrontend/node_modules/vue/index.js)
- [email protected] (/home/alejo/playground/parquesFrontend/node_modules/vue-template-compiler/package.json)

This discrepancy may lead to erroneous functionality. Ensure both versions match.
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 automatically bump up vue-template-compiler to the latest version.

Furthermore, when I attempted to install [email protected], I encountered the following error:

❯ npm install [email protected]
npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected].
npm ERR! notarget In most cases, either you or one of your dependencies is requesting
npm ERR! notarget a non-existent package version.

npm ERR! For more details, refer to the full log:
npm ERR!     /home/alejo/.npm/_logs/2020-11-17T02_52_46_458Z-debug.log

How can I go about resolving this issue?

Answer №1

For a seamless integration of Vue 3 with webpack without relying on vite or vue cli, you can follow these guidelines:

  1. Initialize the package.json as shown below :
{
    "private": true,
    "name": "vue-3",
    "description": null,
   
}
  1. Install the latest version of Vue :

 npm i --save vue@next vue-loader@next

  1. Also, install the necessary dev dependencies which includes @vue/compiler-sfc replacing vue-template-compiler
npm i -D @vue/compiler-sfc css-loader file-loader mini-css-extract-plugin
 url-loader webpack webpack-cli webpack-dev-server
  • @vue/compiler-sfc
  • css-loader
  • file-loader
  • mini-css-extract-plugin
  • url-loader
  • vue-loader
  • webpack
  • webpack-cli
  • webpack-dev-server
  1. Create or modify your webpack.config.js with the provided content :
const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

// Remaining configuration code here

  1. Include a dev script to run your application :
{
    "private": true,
    "scripts": {
        "dev": "webpack-dev-server"
    },
    "dependencies": {
        "vue": "^3.0.2"
    },
    "name": "vue-3",
    "description": null,
    "devDependencies": {
      ...
    }
}

  1. Ensure that your index.html contains the following elements :
<link rel="stylesheet" href="/dist/main.css" />
<div id="app"></div>
<script src="/dist/main.js"></script>

Finally, execute npm run dev and visit http://localhost:8080/

If you prefer to skip the configuration steps, you can clone this REPOSITORY following the provided instructions.

https://codesandbox.io/s/webpack-vue3-kl9k2?fontsize=14&hidenavigation=1&theme=dark

Answer №2

For Vue 3, it is recommended to utilize vue-loader@next

In Vue 3, the SFC compiler package has transitioned from vue-template-compiler to compiler-sfc (refer here for details)

I fully support using Vue CLI for project management as it simplifies handling dependencies, especially during the ongoing transition of the Vue 3 ecosystem where some tools lack migration documentation like vue-loader

If unable to adopt CLI due to an existing Webpack configuration, leverage CLI as a reference. Create a new project on the side, use vue inspect command to analyze the current Webpack setup and review the package.json for necessary dependencies...

Answer №3

Recently, I integrated the Webpacker gem into my Rails project, which includes useful tasks for setting up Vue.

However, it currently installs Vue 2.x along with its loader and template compiler...

To upgrade to Vue 3 and its related dependencies, simply execute the following command:

yarn add vue@next vue-loader@next @vue/compiler-sfc

And just like that, you'll be working with Vue 3!

Answer №4

After manually upgrading a Vue2 application to Vue3, I encountered an error while running unit tests post updating all dependencies.

To resolve the issue, I had to make adjustments to Jest's configuration file as well.

In jest.config.js, ensure the "transform" property is set as follows:

{
  transform: '^.+\\.vue$': `vue-jest`
}

The dependencies I utilized for this transition were obtained from a new Vue3.0 application that I created using the CLI. The following are the dependencies included in my CLI configurations:

  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-0",
    "vuex": "^4.0.0-0"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-unit-jest": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/test-utils": "^2.0.0-0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^7.0.0-0",
    "node-sass": "^4.12.0",
    "sass-loader": "^8.0.2",
    "typescript": "~3.9.3",
    "vue-jest": "^5.0.0-0"
  }

Please note that in my CLI settings, the .eslintrc.js file also underwent some minor alterations for compatibility with Vue3. In a fresh installation, the CLI sets the "extends" property as shown below:

  extends: [
    `plugin:vue/vue3-essential`,
    `eslint:recommended`
  ],

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

Discover the Google Chrome Extension that allows you to easily obtain JSON data from your

Here is the structure I have: And below is my manifest.json: { "manifest_version": 2, "name": "Doktor-MD", "description": "Share links on Doktor-MD through the browser.", "version": "1.0", "permissions": [ "http://www.google.com/" ], "browser_action": ...

Adding Axios package to a Vue 3 project without using the CLI

I'm facing an issue while trying to integrate the Axios package into my Vue 3 project that is not CLI-based. I initially attempted to include the package within the script tags at the top of the page, but that approach failed. Next, I tried creating a ...

The process of generating a querystring from a form using jQuery is not functioning as expected

I am attempting to send an AJAX request, but I am facing an issue where the query string I am trying to construct turns out to be empty. <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>This project dem ...

How to send Multipart form data with a string payload

Many suggestions in regards to this issue recommend utilizing some form of FormData within nodejs for building a multipart form. However, I am seeking to achieve the same result without relying on the FormData library. Instead, I aim to use only request h ...

Scalable Vector Graphics Form Field

I'm looking to enable user input in one of my SVG text fields when they click on it. Any ideas on how to achieve this? const wrapper = document.getElementById('wrapper'); const text = document.getEl ...

I am new to javascript and jquery. I have encountered numerous cases involving audio players

Recently delved into learning javascript and jquery. I managed to create a basic audio player that plays short audio clips. However, I've encountered an issue where clicking the play button on one clip displays stop buttons on all clips instead of on ...

Learn the steps for filling the color area between two points in HighCharts

Is it possible to have a color fill between two points on an area chart when clicked? You can view the current chart here. $(function () { $('#container').highcharts({ chart: { type: & ...

Masonry layout organizes images in a vertical stack, with one image per row

After implementing Masonry on my website, I encountered an issue where all the images stack vertically in a single row once the page loads. Instead, I would like them to stack both horizontally and vertically. You can view the problem on My Jsfiddle. This ...

Discover the steps to linking a dropdown menu to a text input using HTML and JavaScript

I'm currently using Sublime and trying to link a dropdown menu with an input text using html, css, and javascript. When the user selects an option from the dropdown menu, I want the corresponding value to appear in the text input field. For example, i ...

Instructions on integrating Realm SDK with Vue3

I've been utilizing Realm SDK in Vue2 with the following syntax: // file scr/plugins/realm.js import Vue from 'vue'; import {App} from 'realm-web; Vue.prototype.realmApp = new App({id: 'artes-realm-vl12'}) //file scr/main.js ...

jQuery failing to append code after being removed

I need some assistance with an issue I've run into while using jQuery's .remove(). Here is a snippet of code that showcases the problem: $( '.video-button span.glyphicon-play' ).click(function() { $( '#video-player' ).ap ...

The nested jade elements are failing to render

If I have a jade setup with 3 files as follows: 1. //layout.jade doctype html html body block content 2. //index.jade extends layout block content h1 Animals block cat block dog 3. //animals.jade extends index block cat p Meow block ...

Enabling real-time notifications through Express 4 middleware with socket.io integration

I am in the process of developing a real-time notification system utilizing socket.io. Here is the current server-side code I have implemented: bin/www: var app = require('../app'); var server = http.createServer(app); var io = app.io io.attac ...

Tips for adjusting image dimensions with url() method in css

I have successfully incorporated collapsible functionality on my page. I would like to display a down arrow image instead of the default '+' symbol on the right side of the collapsible section. To achieve this, I can use the following CSS code s ...

Tips for restricting the size of uploaded files or the quantity of files in multer express and effectively managing any errors

I am currently working on a code that requires me to set limits on file size or the number of files that can be uploaded. For instance, I want to restrict users from uploading more than 100 files at once or limit the total upload size to 100 mb. However, ...

Angular with Firebase: How to ignore a field in a query

I am curious to see if my current structure is compatible with Firebase, or if I need to make adjustments. Let's take a look at an example using the "/rooms" endpoint, which contains an array of Room objects: export class Room { id: number; p ...

Reset filter when the "All" option is chosen in Vue.js

There is an array of objects that looks like this: obj= [{name: 'joe', job: 'teacher', city: 'miami'}, {name: 'bill', job: 'police', city: 'yorkshire'}, {name: 'sarah', job: 'driver ...

In Vue JS, what is the best way to access my data within a filter function written in Javascript?

One feature I added to our application is a validation check for each row to ensure there are no duplicate column values. While the validation works fine, I'm encountering an issue with deleting rows. For example: https://i.stack.imgur.com/NylYj.png ...

Searching for an object within an array in NodeJS that is not present in another array

One of my challenges involves working with two arrays of objects: var existingUsers1 = []; existingUsers1.push({ "userName": "A", "departmentId": "1" }); existingUsers1.push({ "userName": "B", "departmentId": "1 ...

Delete an <li> element upon clicking a span tag

I've been attempting to fadeOut some <li> elements, however I haven't had any success. Here's my code below: <li class="lclass" id="1"> First Li <span class="removeit" id="1" style="color:#C00;">Remove</span> ...