Combining Vueify with Elixir and Hotloading led to an unexpected error: Uncaught TypeError - property 'indexOf' is undefined

I have successfully configured Elixir to utilize Vueify with a hot reload plugin. The compilation process runs smoothly, but I encounter a console error in my compiled file and the Vue component does not seem to transform into HTML; it still displays the <app></app> tags. When I remove the hot reload plugin from Elixir, the page renders correctly.

The specific error message is:

Uncaught TypeError: Cannot read property 'indexOf' of undefined

The console output is as follows:

[HMR] Attempting websocket connection to http://localhost:3123
app.js:10904 Uncaught TypeError: Cannot read property 'indexOf' of undefined
[vue-devtools] Ready. Detected Vue v1.0.26
[HMR] Websocket connection successful.
[HMR] Updated modules ["resources/assets/js/embeds/html/app.vue"]

Despite receiving messages from hot reloading, the page fails to render due to this error. The error occurs within the compiled app.js file at the following lines:

// compat with < 2.0.0-alpha.7
  if (Vue.config._lifecycleHooks.indexOf('init') > -1) {
    initHookName = 'init'
  }

Below are the relevant files:

gulpfile.js

var elixir = require('laravel-elixir');
var gutil = require('gulp-util');
require('laravel-elixir-vueify');

if (gutil.env._.indexOf('watch') > -1) {
    //  Add the browserify HMR plugin
    elixir.config.js.browserify.plugins.push({
        name: 'browserify-hmr',
        options: {}
    })
}

elixir(function (mix) {
    mix.browserify('embeds/html/main.js', 'public/js/embeds/html/app.js');
});

main.js

var Vue = require('vue')
var App = require('./app.vue')

new Vue({
    el: 'body',
    components: {
        app: App
    },
    created: function() {
        console.log('test');
    }
})

app.vue

<style>

</style>

<template>
    <div id="player-wrapper">
        {{ msg }}
    </div>
</template>


<script>
    export default {
        data () {
            return {
                msg: 'Hello world!'
            }
        }
    }
</script>

index.blade.php

<body>
    <app></app>
    <script type="text/javascript" src="{{ asset('js/app.js') }}"></script>
</body>

Answer №1

There may be an issue with version compatibility between Vue and Vue-hot-reload-api.

For example, [email protected] relies on [email protected], which may only be compatible with [email protected].

In my experience, I encountered this error when using [email protected] with [email protected], although I have not tested the reverse scenario.

A note at the top of Vue-hot-reload-api's Github readme also confirms this issue.

In my case, I resolved it by reinstalling the correct version of vue-hot-reload-api:

npm install --save-dev vue-hot-reload-api@^1.3.2

Make sure to check the versions of your dependencies for compatibility.

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

Issue arises when the value becomes nonexistent following the execution of a

Having an issue with my code where I have one class with a function in it, and another class that imports the first class to use that function. However, after the function is executed, I am not getting the expected value. First class: export class MoveE ...

What is the process of inserting information into a nuxt-link in nuxt.js?

I am currently facing an issue with passing data into nuxt-link. Whenever I click on the link, nuxt-link returns a 404 error and fails to load the file. However, the other two links that use :href and hardcoding seem to be working fine. <template> ...

Basic Node.js messaging application excluding the use of socket.io

Recently, I've delved into learning Node.js and embarked on creating a basic chat application. It appears that socket.io is the go-to option for most developers, but I'm keen on grasping the concept from a more foundational standpoint using GET a ...

The close button on my modal isn't functioning properly

There seems to be an issue with the close button functionality. <div class="modal fade show " id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" style="display: block;left: -6.5%;"> <div class="modal-dialog" ...

Creating a compact, production-ready code using the webapp generator in Gulp

I recently used the webapp generator to scaffold a project, but encountered an issue where the project only worked when accessed through localhost and not when opening the files directly in the browser with a file scheme. The URL http://localhost:9000/ cor ...

Exporting State From Another ReactJS Module: A Step-by-Step Guide

A new project is underway with 3 students who are diving into the world of React for the first time. To make our work more efficient, I suggested dividing the code so that each student could work on a different aspect simultaneously. However, when I attemp ...

What is causing this issue that is preventing me from async rendering Vue components?

I am new to working with Vue and I am attempting to lazy load a Component. However, I encountered an error that seems to be related to a syntax issue. Below is the code snippet: <template> <div class="container"> <h1>Asy ...

Ways to retrieve an object initialized within a function

I'm sorry if my title is a bit confusing. I'm currently working on creating an object that contains key-value pairs of other objects. Below is the code snippet I'm testing in the Chrome console. When I try to create the object using the Cha ...

The setLanguage function in jsPDF does not support rendering different language characters

I'm currently working with jsPDF in Angular 2 and I'm experiencing an issue where my HTML content is not converting successfully into a PDF when it's written in Hebrew. Other languages seem to work fine, but Hebrew is causing a problem. How ...

What is the best way to create a seamless Asynchronous loop?

Adhering to the traditional REST standards, I have divided my resources into separate endpoints and calls. The primary focus here revolves around two main objects: List and Item (with a list containing items as well as additional associated data). For ins ...

Tips for retrieving all values included in the <tr> tags within an html <table>

When the checkbox in the fourth column is clicked, I would like to retrieve all values of td. Additionally, I want to determine the smallest value between ID and Optional ID. <table><form method='GET'> <tr> <th>Name</t ...

Is there a way for me to include a prefix in the path where Vue pulls its component chunks from?

I recently incorporated VueRouter into my project and encountered an issue with the asset URL not being correct. Instead of displaying www.example.com/js/0.main.js The URL it generates is www.example.com/0.main.js Any suggestions on how to include the ...

Plugin combination of Cordova File, InAppBrowser, and File Opener

I am experiencing an issue with opening a PDF file that I have stored using the File Plugin. I have tried using both the InAppBrowser and File Opener Plugin, but neither seem to work. I am currently using the Visual Studio Emulator KitKat for Android. Whe ...

Retrieving a specific item using a key in Vue.js

In my Vue template, I have the following data: 0: { id:1, name:test1} 1: { id:2, name:test2} 2: { id:3, name:test3} While the loop <div v-for="(product, index) in products" :key="product.id"> works perfectly, I am wondering how I ...

When conditions are met, all items are added to the array

In my Angular app, I have a user list that I am trying to filter based on the condition age > 45. However, all users are being pushed into the validForScheme array instead of just those meeting the condition. I am unable to figure out what is going wron ...

What is the reason for XMLHttpRequest overwriting preexisting events?

After clicking a button, I trigger an XMLHttpRequest event. However, I noticed that the original event becomes null once the request is sent. Why does this occur? Is there a way to maintain the original event? document.getElementById('start') ...

Mysterious line break emerges upon displaying JavaScript through PHP

I have a situation where I am using PHP to output JavaScript for a WordPress shortcode. This is what my PHP code looks like: $output="<script type='text/javascript' > jQuery(document).ready(function() { jQuery('#photo{$photo_id}&a ...

Speeding up the loading time of my background images

body { background: url(http://leona-anderson.com/wp-content/uploads/2014/10/finalbackgroundMain.png) fixed; background-size:100% auto; } I have unique background images on each of my sites, but they are large in size and take some time to load due to bein ...

Utilizing AJAX and Javascript to assign text file contents to a JavaScript variable

After attempting to extract a list of words from a txt file and store it in a JavaScript variable for future use, I've encountered an issue. The problem lies in my inability to transfer the variable outside of the onreadystatechange function. Could th ...

Updating the state of an object nested within another object in React JS

So, I have a nested object within another object and I need to update the state of one or more properties in the inner object. This is my current state: const [products, setProducts] = useState({ name: '', type: '', price: '& ...