[Vue alert]: The element #app is missing - Vue.js 2

Not a duplicate: already checked this question and this one; didn't find any clue. Some similar ones are related to Laravel.

Having trouble identifying the changes in my project that have caused the appearance of

[Vue warn]: Cannot find element: #app
.

The setup:

index.html: contains the <div id="app">:

[HEADER]

<div id="app" v-cloak></div>

[FOOTER]

main.js:

import Vue from 'vue';
import Users from './Users.vue';
import App from './App.vue';             // (1)
import Home from './Home.vue';           // (2)
import VueRouter from 'vue-router';      // (3)

Vue.use(VueRouter);

const routes = [
  {path: '/users', component: Users},
  {path: '/', component: Home}
];

const router = new VueRouter({
  routes
});

new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

EDIT: changing the last block to:

$(document).ready(function () {
  new Vue({
    el: '#app',
    router,
    render: h => h(App)
  })
})

did not resolve the issue.

App.vue:

<template>
  <router-view>
</router-view>
</template>

<script>
export default {
  data () {
    return {
      message: "Test message"
    }
  }
}
</script>

Home.vue:

<template>
    [contents]
    [router-links]
</template>

<script>
    [data]
    [methods]
</script>

Whenever I navigate to the index page, the Vue warning is displayed. One suggestion from a related question was that the DOM element might not be ready when the scripts are running. I tried changing the order of imports in main.js (App, Home and VueRouter), as indicated in comments, but it did not work.

Any suggestions on where to look for a solution?

Answer №1

After some investigation, I identified the issue:

index.html:

(...)
      </footer>
   <script src="../dist/build.js"></script>
</body>

The script mentioned in the code above is located in a directory named build. However, webpack generates its own script file dynamically and runs the application from it. This was causing the script to overwrite values that were correctly loaded previously. By removing the ../dist/ directory and commenting out the script line, everything went back to functioning normally.

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

Is there a way to simultaneously adjust the width of all right or left elements?

I am working with a group of sibling div elements and I need to adjust their widths based on the drag and resize of one particular div. When the div is being resized to the west or east, I want to increase or decrease the widths of the other sibling divs ...

Identify data manipulation techniques in VueJS

I am looking to link a data attribute to a function in the methods section, but I am struggling to find the correct method to achieve this. Here is the relevant part of my template: <v-tooltip left v-for="(actionData, action) in ...

The term 'components' has not been defined (no-undef)

Recently integrated Vue into an existing project and encountered a peculiar linting error: error: 'components' is not defined (no-undef) at src/App.vue:13:3: 11 | 12 | @Component({ > 13 | components: { HelloWorld }, | ^ 14 | }) ...

Reactjs not rendering image properly

Having issues loading an image in a project created with create-react-app due to a persistent parsing error. Check out the code below: 1 import React, { Component } from 'react' 2 import profile from './profile.png' 3 4 class ...

What is the process for linking read-only methods to Redux object instances?

Let's say I have a "user" object stored in redux, with fields for first name and last name (interface User { firstName : string, lastName : string} if using typescript). After retrieving a user from redux, I want to obtain the full name of the user by ...

Is it possible for you to provide both a status code and an HTML webpage?

I've been working with the express framework in node, but I'm unsure if what I'm doing is best practice. I want to send a specific status code such as res.status(200).send("Success"); when the form input matches the server, and another statu ...

How can you transfer data from a jQuery function to a designated div element?

I'm struggling to transfer data from a function to a specific div, but I can't seem to make it work. I'm in the process of creating a gallery viewer and all I want is to pass the counter variable, which I use to display images, and the total ...

Ways to determine the occurrence rate of a specific value within a collection of dictionaries?

Consider the array of dictionaries below: var dictionary_demo = [ [ {country: "georgia", value: sunny}, {country: "france", value: rainy} ...

When the Popover appears in ShadCN, the input field unexpectedly takes focus

This unique component incorporates both Popover and Input functionality from shadcn. An issue I have encountered is that when I click on the Input to trigger the Popover, the Input loses focus and the cursor moves away from it. Expected outcome: Upon c ...

Looking for assistance with navigating through this URL using Python (requests, beautifulsoup, or selenium) or Javascript (node js, puppeteer)?

While attempting to gather data, I encountered an interesting pagination challenge on the following URL: My expertise in Web Scraping was put to the test as this website implemented a unique JavaScript-driven pagination. For the initial 5 pages, it simply ...

Can you group polygons in layers using Phaser?

My goal is to animate two polygons: one that remains stationary and another that changes shape while moving. The challenge is to ensure that the stationary polygon always stays on top when overlapping. This is my proposed solution: (function() { "use ...

Is the next function triggered only after the iframe has finished loading?

First and foremost, I understand the importance of running things asynchronously whenever possible. In my code, there exists a function known as wrap: This function essentially loads the current page within an iframe. This is necessary to ensure that Jav ...

Navigating through PWAs and implementing deep linking in both single page applications (SPAs) and multi-page applications

QUESTION: How can navigation, history, and deep-linking be managed in a PWA without relying on a heavy JS Framework? Tasked with transitioning an existing shopping website from Angular 1 SPA to a Multi Page App (MPA) PWA, I find myself grappling with desi ...

Troubleshooting Vue template issues with updating values in the composition API

I am facing an issue with a functional component: export default defineComponent({ name: 'MovieOverview', components: { ExpandedMovieInformation, }, setup() { let toggleValue = false; const toggleExpandedMovieInformation = (m ...

Converting Date Format According to Visitor's Time Zone in VueJs/JS

I have a Date in string Format: 2020-07-13 7:07 AM (which is indian time). I am looking to adjust this time according to the browser's time zone, which could be either in the US or Africa. I have attempted various methods to convert it accurately. He ...

Creating a CSS animation to slide a div outside of its container is

I currently have a flexbox set up with two adjacent divs labeled as DIV 1 and DIV 2. By default, both DIV 1 and DIV 2 are visible. DIV 2 has a fixed width, occupying around 40% of the container's width. DIV 1 dynamically adjusts its width to ac ...

Tips for sending data to PHP using AJAX POST

When attempting to send data through AJAX to a PHP file, I am encountering an issue where it returns NULL. I have verified that all 'val()' functions are returning the correct values with the following AJAX code: $.ajax({ url: '../util ...

JSDOM failing to retrieve complete list of elements from webpage

I'm currently struggling with a simple webscraper using JSDOM. Here's the code snippet I've been working on: const axios = require("axios"); const jsdom = require("jsdom"); const { JSDOM } = jsdom; let v = "15" ...

The concept of asynchronous behavior in ReactJS using the useState hook

I am working on a page to display a list of products. I have included an input file button that allows users to select multiple images. After selecting the images, I use an API to upload them to the server and show the progress visually in the UI with the ...

Display a random div element in jQuery without specifying a specific class

I have a dynamic list that I am displaying in a div as shown below <div class="cards card1"> <div class="front"> <p>Front 1</p> </div> <div class="back1" style="display: none"> <p>Back 1</p> ...