Rollup.js with Vue.js displays an HTML comment instead of rendering Vue HTML content

As I delve into the world of Vue.js, I am encountering some challenges with rendering a simple interpolation within my local development application.

The Issue

  • Strangely, the Vue instance displays an HTML comment of createElement
<body>
  <script id="__bs_script__">
    //<![CDATA[
    document.write("<script async src='/browser-sync/browser-sync-client.js?v=2.26.7'><\/script>".replace("HOST", location.hostname));
    //]]>
  </script>
  <script async="" src="/browser-sync/browser-sync-client.js?v=2.26.7"></script>

  <!--function (a, b, c, d) { return createElement(vm, a, b, c, d, true); }-->

  <script src="/scripts/main.js"></script>
</body>

Upon using "step into next functional call" from new Vue(..): https://i.sstatic.net/VPRvA.png

Main.js - Upon observing that nunjucks was utilizing the {{ }} mustache tokens in my gulp build, I made sure to modify the delimiter in the Vue instance to << >>. This validation assured me that they appear in the .tmp folder where the app is served.

import Vue from 'vue'
var example1 = new Vue({
    delimiters: ['<<', '>>'],
    el: '#example-1',
    data: {
      items: [{
          message: 'Foo'
        },
        {
          message: 'Bar'
        }
      ]
    }
  });

HTML

<body>
  <ul id="example-1">
    <li v-for="item in items">
      << item.message >>
    </li>
  </ul>

  <script src="/scripts/main.js"></script>
</body>

Gulp file

  • The HTML output is generated by task nunjucksHtml.
  • The JS bundles are managed by task scripts.
  • There seems to be no issue with browsersync, but it stands out as one of the discrepancies between the local IIS site with static HTML and JS that functions seamlessly.
const { src, dest, watch, series, parallel } = require("gulp");
const gulpLoadPlugins = require("gulp-load-plugins");
const browserSync = require("browser-sync");
const del = require("del");
const { argv } = require("yargs");

const $ = gulpLoadPlugins();
const server = browserSync.create();

// More code for tasks is present, not displayed here

let serve = series(
    clean,
    parallel(nunjucksHtml, scripts),
    startAppServer
);

exports.serve = serve;

Package.json (essential parts only)

{
  "private": true,
  "engines": {
    "node": ">=4"
  },
  "dependencies": {
    "vue": "^2.6.10"
  },
  "devDependencies": {
    "@babel/core": "^7.1.2",
    "@babel/preset-env": "^7.1.0",
    "browser-sync": "^2.2.1",
    // Other dependencies listed here
  },
}

Resolutions Attempted

  • I recreated the example on CodePen and hosted it locally with IIS alongside static HTML with inline JavaScript, which operated flawlessly.

Answer №1

There were two crucial aspects to address in this situation:

  1. nunjucks render was causing issues with resolving {{ property }} and completely removing it from the output. To resolve this, I modified the variable syntax of nunjucks as follows:
    .pipe(
      $.nunjucksRender({
        envOptions: {
          tags: {
            variableStart: '{#',
            variableEnd: '#}'
          }
        }
      })
    )
  1. By default, when importing Vue, the runtime-only module is loaded due to its declaration in the modules section of vue/package.json. As per the installation guidelines:

If you require template compilation on the client side (e.g., passing a string to the template option or mounting to an element using its in-DOM HTML as the template), you will need the compiler and hence the entire build

Hence, my import statement had to be tweaked to:

import Vue from 'vue/dist/vue.esm.js'

Answer №2

you can keep most of the tags as they are, just include the {% code %} tag like this:

{% code %}
  <span>
   <p>{{text}}</p>
  </span>
{% endcode %}

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

Unlocking JSON Keys Using Dashes

When working with JSON objects, we typically access elements using dot notation. For example, var obj = {"key": "value"}; var val = obj.key;. However, what if the key contains hyphens, like in this case: var obj = {"key-with-hyphens": "value"};? Do we ne ...

Error encountered in React JS: The property being accessed is undefined and therefore cannot be mapped

I have been working on a MERN project and I am currently at the stage where I am integrating the frontend and backend using Axios. However, I have encountered some issues. One of the most common errors I am facing in my list screens is: TypeError: Cannot r ...

What is the best way to handle asynchronous requests in frontend development with Nuxt.js?

Recently delving into Vue and Nuxt, I have been grappling with a query surrounding asynchronous requests. My understanding so far is that utilizing asyncData along with axios in Nuxt allows for fetching data that can be showcased on the frontend. However, ...

Double the names in a single <input>

Is it possible to assign two different names within a single input tag, like this: <input type='text' name='food' name='user_search_input'>? In my PHP file, I intend to use the input in two separate "if" clauses - one fo ...

Having trouble making the jQuery post method work to invoke a function in a Coldfusion component

While attempting to invoke a cfc method through ajax using jQuery's post() method, I repeatedly encounter an error message stating that "the xxx parameter to the yyy function is required but was not passed in". Below is the cfc function in question: ...

Error: Angular does not recognize session storage reference

While my project is up and running, I have encountered an error in the terminal. let obj = { doc_id: sessionStorage.getItem('doc_id'), batch_no: sessionStorage.getItem('batch_no') } I attempted to make adjustments by a ...

Exploring the process of customizing native classes with Vue.js

Within vue-awesome-swiper, there's a standard class called this: .swiper-button-next { position: absolute; right: 46% } The task at hand is to adjust this CSS code only for right-to-left layouts, like so: .swiper-button-next { position: abso ...

Changing the color of tabs using inline styles in material ui does not seem to work

I am brand new to using material ui and have been attempting to alter the colors of the selected tab. Currently, the color is a dark blue shade and I am aiming to change it to red. I tried applying inline styles, but unfortunately, there was no change. C ...

Tips on personalizing rows in an xlsx spreadsheet prior to exporting

When I receive an array of objects (dicts) as input, it looks something like the example below. const data = [ { id: 1, serviceId: 1, title: "A", model: "A", }, { id: 1, serviceId: 1, title: "T", model: "b", ...

The URL dynamically updates as the Angular application loads on GitHub Pages

Encountering an unusual issue when trying to access my angular website on GitHub pages. The URL unexpectedly changes upon opening the page. Please check it out at this link: The original expected URL should be However, as the page loads, the URL gets alt ...

Transfer numerical values from PHP to JavaScript using individual files

What is the best way to pass variables from PHP to JavaScript when they are in separate files? Is it possible to achieve this without using AJAX, or is AJAX necessary for this task? If AJAX is required, how can I implement it? test.php <?php $a = 5; $ ...

Customized settings saved in local storage using JavaScript

Here is the script I am currently using for my app: <script> if (localStorage.getItem("0") === null) { //do nothing } else if(localStorage.getItem("1")===null{ } else if(localStorage.getItem("2")===null{ } else if(localStorage.getItem("3")===null ...

What is the best way to trigger an AJAX request when a user navigates away from a webpage or closes the

The Challenge at Hand Greetings, I am currently developing a database-driven game that involves users answering questions and earning the right to change the question by providing the correct answer. However, I have encountered a significant issue which ...

Eliminate a specific choice from a drop-down menu in an Angular application

I am implementing a feature where clicking on a button adds more select drop downs. I want to ensure that the selected options in these new dropdowns do not duplicate any already chosen options. Below is the code snippet used for the select drop down: < ...

What is the best way to incorporate the {id} property into my Next.js dynamic route using the Context API?

I am encountering an issue with passing the ${id} property to my dynamic route [id]>page.jsx, located within the CartItemPage.jsx file. The setup involves using the Context API, similar to React, where I maintain an array of CartItems to render the Cart ...

Issue with toggling options in q-option-group (Vue3/Quasar) when using @update:model-value

I'm a newcomer to the world of Quasar Framework and Vue.js. I recently tried implementing the q-option-group component in my simple application but encountered an issue where the model-value and @update:model-value did not toggle between options as ex ...

Learn how to change the input source in Ratchet's chat app to come from a text box on the webpage instead of the console

I followed the guidelines on to create a chat app. However, I now want to input data from a text box instead of using conn.send() in the console. How can I achieve this using php? I was successful in redirecting the sent message to an html element like ...

What could be the reason my Backbone view is failing to render?

Can anyone help me troubleshoot why this template isn't rendering properly in my backbone views? Any insights would be greatly appreciated! Below, I've included the code from my jade file for the views and the main.js file for the backbone js scr ...

Unable to locate module: Unable to locate the file './Header.module.scss' in '/vercel/path0/components/Header'

I encountered an error while attempting to deploy my next application on Vercel. I have thoroughly reviewed my imports, but I am unable to pinpoint the issue. Module not found: Can't resolve './Header.module.scss' in '/vercel/path0/comp ...

Loading `.obj` and `.mtl` files in THREE.js with accompanying PNG textures

I am facing an issue while attempting to load an mtl file with reference to png textures for my obj model. The error I am encountering is as follows: TypeError: manager.getHandler is not a function Below is the snippet of my three.js code: var loadOBJ = ...