Error: Unable to mount component - template or render function is undefined in Symfony Vue.js Encore application

I am currently working on integrating vue.js with Symfony. While this Vue.js configuration worked flawlessly in Laravel, I am facing difficulties with Symfony and unfortunately, I need to use Symfony for this particular project.

My webpack.config.js is set up based on the Symfony documentation.

var Encore = require('@symfony/webpack-encore');

Encore
    // defines the directory where compiled assets will be stored
    .setOutputPath('web/build/')

    // specifies the public path used by the web server to access the assets directory  
    .setPublicPath('/build')

    // will generate web/build/app.js and web/build/app.css
    .addEntry('vue', './web/assets/js/vue.js')

    .enableVueLoader()
    ...
;

// export the final webpack configuration
module.exports = Encore.getWebpackConfig();

The vue.js file can be found at web/assets/js/vue.js

import Vue from 'vue'

Vue.component('example-component', require('./components/Example.vue'));

const app = new Vue({
  el: '#app'
})

Here's an example component:

<template>
    <div>
        Hello!
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

In my Twig view (the div with id app is located in base.html.twig):

{% extends 'base.html.twig' %}
{% block content %}

    <example-component></example-component>

    ...
{% endblock %}
{% block jsvendors %}
{% endblock %}

Although the build was successful, I encountered the following error in the console:

[Vue warn]: Failed to mount component: template or render function not defined.

found in

---> <ExampleComponent>
       <Root>

I'm unsure of what I might be doing wrong. I want to utilize vue.js by adding a few components to different sections of my pages, similar to how it was implemented in Laravel.

Thank you for any help or insights provided.

Answer №1

Make sure to include the default keyword when requiring:

Vue.component('sample-component', require('./components/Sample.vue').default);

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

Tips for resolving the npm ResourceUnavailable issue

Hey there! I'm currently experimenting with React. In my folder, I've got nodejs along with npm and npx files installed. While debugging, I've deleted and reinstalled this folder multiple times. However, no matter what directory or command I ...

When using the Vuetify data table in single-select mode, choosing one row automatically selects all the other rows

I am having trouble selecting a single row from the table and then emitting the selected item. Currently, when I select one row, all rows become selected but only the first one encountered is saved to the model (as the selected variable). Could you provi ...

The Vuex state is being modified by an action, yet the associated computed property fails to react accordingly

I am facing an issue with fetching data from firebase using a store.js file that I have imported into the main.js. The problem is that the data does not display correctly when the page loads. However, when I check the console.log in mutations, it shows t ...

Creating a custom Docker image with a specified version of the Node package installed

My goal is to create a Docker image with a node package installed. If I hardcode the package version in the Dockerfile, everything works fine (@14.0.0): FROM stefanscherer/node-windows:12.16.1-nanoserver-1909 RUN npm install -g @sitecore-jss/<a href="/ ...

Dynamically add index to attribute as it updates

Having an issue with my dynamic button element: <button v-on:click="changeRecord(element)" v-b-modal.modal-5>Aendern</button> This button is generated dynamically within a v-for loop. Instead of manually including the attribute name like v-b- ...

Creating dynamic tables in Vue JS is a powerful feature that allows developers to generate

I have been trying to implement a button that, when clicked, will generate a new table. Unfortunately, my search for a solution has come up empty so far. Most tutorials I found focus on manipulating rows in a single table rather than creating a new one fro ...

Navigating through Node's asynchronous behavior

I am currently developing a web scraper that gathers data about various shirts from a specific website. I have successfully set up all the necessary NPM packages in Node.js to scrape the information and save it to a CSV file. However, I have encountered ...

Ways to prevent event bubbling in the case of a checkbox input alteration?

Description I am looking to create a table component with checkboxes, but I am facing an issue. Whenever I click on a checkbox, the click event is also triggered for the table row and cell containing the checkbox, which is not what I want. I have tried us ...

What is the process for computing two input values and placing the outcome in a different input field using Vue.js?

Check out my input fields below: <input v-model="form.sale_quantity" @change="computed" type="number" class="form-control" name="sale_quantity" id="sale_quantity" placeholder="Quantity&quo ...

npm error - Ensure that the package.json contains a correct "main" entry for the file

After attempting to run npx create-react-app, I encountered an error that has prevented me from using npm for any tasks. Despite uninstalling and reinstalling Node multiple times, the same issue persists. The error message is as follows: npm WARN config ...

Replicate the action of highlighting a section of a website and copying it to the clipboard using JavaScript

I am currently in the process of transferring an outdated application to a new platform, but I'm facing difficulty understanding the changed JavaScript code. My goal is to find a parent HTML element named "output" and then select all its child elemen ...

After redirection to a new page, the Ionic-vue menu malfunctioned

I have developed a reusable header component named Header, which contains an IonMenu component for consistency across pages. The menu is associated with the IonRouterOutlet as per the documentation, but I am encountering an issue when navigating between pa ...

Ways to expose a components prop to its slotted elements

I've set up my structure as follows: <childs> <child> <ul> <li v-for="item in currentData">@{{ item.name }}</li> </ul> </child> </childs> Within the child component, t ...

Why are there so many modules being installed with `npm install` when I only need to install two?

Here is my package.json configuration: { "private": true, "devDependencies": { "gulp": "^3.9.0", "laravel-elixir": "*" "bootstrap-sass": "^3.0.0" } } After running npm install, I ended up with a whopping 800 modules ranging from "abbrev ...

What is the process for configuring a custom location for a local installation of an npm package?

Can you set a custom destination for package installation with npm install, using a command flag or environment variable? Usually, npm installs packages in the local directory's node_modules, but I need them to be placed in a different location like ...

Micro Frontend: Implementing a Pubsub System for Scalable Front-End Architecture

Currently, I am developing a large-scale application using the innovative micro front end architecture. The application is split into 5 Micro Apps: (micro-app-A (developed in Vue), micro-app-B (built with Vue), micro-app-C (using Angular), micro-app-D (cre ...

Vuetify's v-text-field not properly aligning text to the center

The alignment of the text in v-text-field is causing issues for me, as I am unable to center it. Despite attempting various solutions, I have not been successful. 1. <v-text-field type="number" class="mr-2 text-center"></v-te ...

Testing-library does not seem to recognize SFC styles

I've been working on implementing unit tests in our Vue codebase, but I'm running into some trouble when it comes to testing the visibility of an element. Even though I render the component as per usual and following the examples provided in the ...

Having trouble with yarn install? Keep receiving the error message "Other managers are not allowed"?

Recently, I began using the yarn package manager for one of my projects. To get started, I globally installed yarn using sudo npm install yarn -g. However, when attempting to install dependencies with yarn install, I encountered the following message on t ...

In npm 5.5, what sets npm update apart from npm install @latest?

While reading the information about npm update, I came across a statement that when using it on global packages, such as npm update package-name -g, it should update to the @latest version. Unfortunately, this method did not work for me. As an alternative ...