Error: Cannot locate module: Vue not found, incorrect path specified

I am facing an issue with my webpack configuration. I have placed my webpack.config.js and node_modules in a subfolder. When attempting to run the command npm run build, I encounter the following error:

ERROR in ../public/Vue/Components/Rating.vue Module not found: Error: Can't resolve 'vue'
. I have been trying to troubleshoot this for the past 3 hours without success.

The folder structure of my project is as follows:

project/
 +public/
    Vue/
      Components/
         Rating.vue
      main.js
    Dist/
 +webpack/
   webpack.config.js
   package.json
   node_modules/

Here is my webpack.config.js setup:

var path = require('path');
var webpack = require('webpack');

var target = '../public/Vue/main.js';

var output = {
    path: path.resolve(__dirname, '../public/Dist/'),
    filename: 'default.js'
}


module.exports = {
  context: __dirname,
  entry: target,
  output: {
    path: output.path,
    filename: output.filename
  },

  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    },
    extensions: ['*', '.js', '.vue', '.json'],
  },

module: {
    rules: [
      ... // load loader
    ]
  },
 ....
}

In my main.js file, I import Vue and Rating component as follows:

import Vue from 'vue';
import Rating from "./Components/Rating.vue";

new Vue({
  el: '#app',

  data() {
    return {
      content: "Hello World",
    }
  },

  components: {
    Rating,
  }
});

I would appreciate any help or guidance on resolving this issue :)

Error messages received:

ERROR in ../public/Vue/main.js
Module not found: Error: Can't resolve 'vue' in 'C:\xampp\htdocs\project\public\Vue'
 @ ../public/Vue/main.js 1:0-22


ERROR in ../public/Vue/Components/Rating.vue
Module not found: Error: Can't resolve 'vue-style-loader' in 'C:\xampp\htdocs\project\public\Vue\Components'
 @ ../public/Vue/Components/Rating.vue 2:2-297
 @ ../public/Vue/main.js

Answer №1

This particular question holds a strong position on Google search results, prompting me to include a guide for Vue 3 settings. When using Webpack 5 and Vue 3 together, the webpack config alias should be updated as follows:

resolve: {
    extensions: [ '.tsx', '.ts', '.js', '.vue' ],
    alias: {
        'vue': '@vue/runtime-dom'
    }
},

If encountering transpilation errors, consider implementing this alternative solution:

    alias: {
        'Vue': 'vue/dist/vue.esm-bundler.js',
    }

Hoping that this information proves helpful and saves time for fellow developers.

Answer №2

It seems like this error may occur when you forget to run the command npm install

Can you please verify if the directory

C:\xampp\htdocs\project\public\Vue\node_modules
contains the folder named vue?

Answer №3

One common scenario is forgetting to remove the alias after migrating from vue2 to vue3 and completing the migration build without removing the @vue/compat helper.

chainWebpack(config) {
// Used for upgrading vue2 to vue3
config.resolve.alias.set('vue', '@vue/compat');

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

js The correct value is not being set to the div's style.top

function gamestart(){ var gr; var gr = true; console.log(gr==true); if(gr == true){ console.log("we have activated pointer key detection dear Mr.ketsebaot") document.onkeydown = checkk; } } function checkk(e){ cons ...

Retrieve the variable only once a response has been received from the POST request

Is there a way to update a variable in my component only after receiving a response from a POST request? Here is the code in component.ts: formSubmit() { this.sent = this.submitProvider.sendByPost(this.form); this.formSent = this.submitProvider.f ...

Using Vue to set an active class on an element and retrieve the current DOM element

I am attempting to apply a class called "active" to the currently selected element without using v-for. When the element is clicked, I assign event.target to the "selected" property. To compare each individual element with the one stored in "selected", I n ...

Automatically close the multiselect dropdown when the user interacts outside of it (varied scenario)

For those interested, check out this jsfiddle link: http://jsfiddle.net/jaredwilli/vUSPu/ This specific code snippet focuses on creating a multi-select dropdown feature. When a user chooses options from the dropdown and then clicks outside of the menu are ...

Troubleshooting unit tests in Vue CLI 3 with WebStorm: resolving breakpoint issues with the debugger

Query What steps should be taken to trigger a breakpoint in WebStorm? Is it mandatory to set the %NODE_DEBUG_OPTION%? If so, how can this be done when using vue-cli.service? Instructions to replicate: Create a new Vue project by running: vue create my ...

Identifying changes in value in any scenario, jQuery

When I click on a button and change the input value, I want an alert to display 'Ok Done', but it's not working as expected. The input value may contain both numbers and letters. $("#myTextBox").bind("change paste keyup", function() { ...

Extracting data from websites: How to gather information from dynamic HTML elements

On the website I am exploring, there is a dynamic graph with descriptions below it that keep changing. My goal is to extract all these trajectory descriptions. The HTML code snippet related to the description area looks like this: <div class="trajDesc ...

Incorporate personalized feedback into a datatable with server-side processing

Trying to implement server-side processing for a datatable loaded from an AJAX response using this specific example The server response being received is as follows: {"msg":null,"code":null,"status":null,"result":[{"aNumber":"3224193861","bNumber":"32159 ...

[Vue alert]: Issue with rendering: "TypeError: Unable to access property 'replace' of an undefined value"

I'm currently working on a project similar to HackerNews and encountering the following issue: vue.esm.js?efeb:591 [Vue warn]: Error in render: "TypeError: Cannot read property 'replace' of undefined" found in ---> <Item ...

Ways to parse a JSON array using Javascript in order to retrieve a specific value if it is present

Below is the JSON code stored in an array: { "kind": "urlshortener#url", "id": "http://goo.gl/2FIrtF", "longUrl": "http://hike.com/?utm_source=facebook", "status": "OK", "created": "2015-09-22T13:45:53.645+00:00", "analytics": { "allTime": { ...

The functionality of Selection.modify is unfortunately limited when it comes to input and textarea elements in Firefox

Check out this demonstration (jsfiddle link): const input = document.querySelector('#input'); const textarea = document.querySelector('#textarea'); const div = document.querySelector('div'); const x = (e) => { if (e.ke ...

The comparison between 'typeof error' and 'undefined' reveals that the data is

I am encountering an issue with a piece of code that is generating an error, and I have been unable to find a suitable solution in JavaScript. var data = new FormData(); $.each(files, function(key, obj) { data.append(o ...

Provide a numerical representation of how frequently one object value is found within another object value

Account Object Example in the Accounts Array: const accounts = [ { id: "5f446f2ecfaf0310387c9603", picture: "https://api.adorable.io/avatars/75/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6b7d7a666 ...

Modifying an @Input element within a component does not result in any changes being reflected in the parent component

Here is the scenario with my component: @Component({ selector: 'child' }) export class ChildComponent { @Input() childObject: ChildObject; changeObject(newObject: ChildObject){ childObject = newObject; } } After calling ...

Barba.js Revolutionizes Page Reloading for Initial Links

On my Wordpress site, I am using Barba js v.2 for page transitions. However, I have encountered an issue where I need to click on a link twice in order to successfully change the page and make the transition work. Interestingly, the first time I click on t ...

Ensuring the accuracy of user input

Can someone assist me with comparing two dates in JSP? I need validation that alerts the user when a future date is entered. The start date or end date should not be in the future. The date format is 12-5-2011 10:51:49. Any help would be greatly apprecia ...

How can we create responsive websites?

Since starting my Software Developer studies about 3 months ago, I've been working on a website project for a driving school with a team of four. The issue we're facing is that when we transfer and open files between laptops, the website layout a ...

Disregard the JSON formatting and extract solely the values

After extracting data from an API, the format of the returned information looks like this: [{"id":21},{"id":22},{"id":24}] Next, I need to send this data to a database using a different API. However, the format for sending should be like this: [21,22,24] ...

Unable to access parameters from Pug template when using onclick event

I am facing an issue with my pug template test.pug. It contains a button that, when clicked, should call a function using parameters passed to the template from the rendering endpoint. Below is the structure of my template: doctype html html head tit ...

Using JavaScript Functions to Resize Buttons and Change function on Click

I have a button in my code that triggers CSS changes by adding and removing classes. The JavaScript for this function works as intended - clicking once adds the class, clicking again removes it, and so on. However, I also implemented a feature to remove t ...