Unusual compilation issue encountered in Vue when trying to use a template for a slot

I encountered a strange issue where my Vue compiler was refusing to render the default named slot of a child component.

Error: Codegen node is missing for element/if/for node. Apply appropriate transforms first.

Even my VSCode highlighted this problem and provided me with the following advice:

Cannot read properties of undefined (reading 'type'); Each *.vue file can contain at most one top-level block; Contents will be extracted and passed on to @vue/compiler-dom, pre-compiled into JavaScript render functions, and attached to the exported component as its render option.

I attempted to resolve this by simply installing the @vue/compiler-dom module, but it did not work.

I am currently stuck on how to overcome this issue.

Parent_component.vue

<!-- ___ -->
<template>
<!-- ^^^ -->
    <div class="entrancePage">
        <next-pop-up v-model:show="showPopUp">
            <div class="recreatePasswordPopUp">
                <!-- __________________________ -->
                <template v-if="showPopUp" #header>
                <!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
                    Password Recovery
                </template>
                
                <div @click="showPopUp = false" class="primary-button">
                    Great!
                </div>
            </div>
        </next-pop-up>
    </div>
</template>

<style scoped lang="scss" src="./style.scss"></style>

<script src="./script.js"></script>

nextPopUp.vue

<template>
    <div class="popUp" v-if="show" @click.stop="hide">
        <div @click.stop class="popUp__content">
            <div @mouseover="setHoverState(true)" @mouseleave="setHoverState(false)" class="popUp__content__closeBtn" @click="hide">
                <img :src="`/img/UI/${ hoverState ? 'cross-active.svg' : 'cross.svg'}`" alt="">
            </div>

            <!-- __________________ -->
            <slot name="header"></slot>
            <!-- ^^^^^^^^^^^^^^^^^^ -->
        </div>
    </div>
</template>

<style scoped lang="scss" src="./style.scss"></style>

<script src="./script.js"></script>

Answer №1

It may not be the exact solution, but I suggest that all templates should be at the top level. Consider revising Parent_component.vue like this:

<template>
    <div class="entrancePage">
        <next-pop-up v-model:show="showPopUp">
            <!-- __________________________ -->
            <template v-if="showPopUp" #header>
            <!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
                Password Recovery
            </template>
       
            <div @click="showPopUp = false" class="primary-button">
                 Great
            </div>
        </next-pop-up>
    </div>
</template>

You'll just need to find an alternate way to apply your recreatePasswordPopUp class

Answer №2

For proper convention, the <template #header> tag should be placed at the top level of the block. It is advised to adjust the template of Parent_component accordingly.

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

Automatically refresh the D3 Sunburst visualization when the source json is modified (items added or removed)

I'm a beginner in D3 and I'm attempting to update the chart dynamically if the source JSON is modified. However, I'm facing difficulties in achieving this. Feel free to check out this plunkr Js: var width = 500, height = 500, radi ...

Tips for saving a value within a jQuery function for future use in a different function

I have a situation where I receive a value from a jQuery function that I need to pass to another function. How can I achieve this? jQuery.getJSON(url+"&startDate="+startDate+"&endDate="+endDate+"&jobId="+jobId+"&type="+type, function(data) ...

Coding with Angular 4 in JavaScript

Currently, I am utilizing Angular 4 within Visual Studio Code and am looking to incorporate a JavaScript function into my code. Within the home.component.html file: <html> <body> <button onclick="myFunction()">Click me</button> ...

Can a single page be used to send email?

My PHP form is currently sending data to another page, and the layout does not look good. I want to keep the form on the same page so that when a user fills it out, the information is submitted without redirecting. If any of the inputs are empty, I would l ...

Apply CodeMirror theme and plugins using an HTML attribute

On my website, I have implemented a CodeMirror text area from . <form><textarea id="code" name="code" codemirror-type='lineNumbers: false, styleActiveLine: true, matchBrackets: true;'>CODE HERE</textarea></form> I added ...

What is the best way to incorporate Ajax into a Rails application?

Check out the Webpage Design I am currently working on a Todo List that includes various Todo Items. Each incomplete task has a button called "Mark Item as Done" next to it, which triggers the button_to method when clicked. I am facing challenges in imple ...

React-highlightjs failing to highlight syntax code properly

I'm currently using the react-highlight library to highlight code snippets in my next.js application. However, I've encountered an issue with the code highlighting when using the a11y-dark theme. https://i.stack.imgur.com/ip6Ia.png Upon visitin ...

Is it possible to utilize Jsoup to extract specific portions of JavaScript code from a webpage?

I am looking to extract data from the following script: $(document).ready(function(){ $("#areaName").val(1);$("#state").val(29);$("#city").val(1); $("#subareaName").val(1);$("#lane").val(1); } Specifically, I need to retrieve values such as areaName ...

Issues encountered when implementing server-sent events in a project built with Node.js and React

I've been working on implementing server-sent-events into my Node.js and React application. After doing some research and following tutorials online, I found this particular site to be very helpful and straightforward. The main objective is to have a ...

I'm wondering why my positive numbers aren't displayed in green and negative numbers in red

I am currently working on a commodities quotes widget. I have already set up the 'Current' and '24-hour' divs, but I'm facing an issue where positive values are not displaying in green and negatives in red as intended. I have check ...

Establishing a PHP session variable and then initiating a redirect to a new page through the HREF method

I am working on a table that pulls IDs from a MySQL table named auctiontable and displays them in rows. Currently, I can easily append ?aid="1"or ?aid="2" to the end of the href attribute to utilize $_GET. However, I want to prevent users from controllin ...

Comparison: Traditional Polling vs Using hidden iFrame for Ajax history tracking

Situation Keeping track of changes in the URL hash and ensuring proper functionality for the forward/back buttons are essential tasks for libraries that manage Ajax history. There are two main approaches to implementing these libraries. One option is to h ...

What is the best way to implement a dynamic Menu Component in next.js?

Hello friends! I am currently working on a Next.js web app with a Menu Component that fetches data dynamically through GraphQL. I really want to achieve server-side rendering for this menu component. My initial attempt to use getStaticProps() to render the ...

Implement a vertical scrolling animation in datatables

I am trying to utilize datatables to display all data. My goal is to have the data automatically scroll row by row every 3 seconds. This is my code, and you can also check it out on jsfiddle The intention is to showcase this data on a large screen. < ...

Managing the React Router component as a variable

I'm currently working on integrating React-Router into an existing React app. Is there a way to use react-router to dynamically display components based on certain conditions? var displayComponent; if(this.state.displayEventComponent){ {/* ...

When attempting to utilize res.sendfile, an error arises indicating that the specified path is incorrect

I am facing an issue with my Express.js server and frontend pages. I have three HTML and JS files, and I want to access my homepage at localhost:3000 and then navigate to /register to render the register.html page. However, I am having trouble specifying t ...

Determining the successful completion of an ajax request using jQuery editable plugin

I recently started using Jeditable to enable inline editing on my website. $(".video_content_right .project_description").editable(BASE_URL+"/update/description", { indicator: "<img src='" + BASE_URL + "/resources/assets/front/images/indicator ...

Using javascript, hide or show a div without using jquery or the display:none property

I am looking for a way to show/hide a div up and down, but I have some requirements: I cannot use jQuery: toggle(), slideToggle(), fade, animate, etc. all use display: none, and I need the div to still occupy space in the DOM (I will be processing things ...

Identify when two calendar dates have been modified

Creating a financial report requires the user to select two dates, search_date1 and search_date2, in order for a monthly report to be generated. Initially, I developed a daily report with only one calendar, where I successfully implemented an AJAX script ...

Guidelines for submitting a form using ajax in Vue version 2.6

Being new to Vue, I am exploring different ways to submit a form. Below is the simple form that I have created: <form :action=" appUrl +'ConnectionHandler'" method="post" enctype="multipart/form-data"> <fieldset id="fileHandlin ...