Guide to utilizing the compiler-inclusive build (Vue, Typescript, Webpack)

I encountered an issue:

You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

My project involves Vue, Typescript, and Webpack, but I am unable to find a solution to resolve this error. Here's what I have attempted so far:

  • Added
    "vue": { "runtimeCompiler": true }
    to package.json
  • Utilized
    new Vue({render: h => h(MyComponent)}).$mount()
    (already implemented)

The crucial sections of the code are as follows:

# webpack.config.js

module.exports = {
  target: 'node', // To make use of Node API through electron
  entry: 'app/index.ts',
  output: { path: '/dist', filename: 'frontend.js' },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        include: /app/,
        options: { appendTsSuffixTo: ['/\.vue$/'] }
      }
    ]
  },
  resolve: {
    extensions: ['.ts', '.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js'
    }
  },
  externals: [nodeExternals()]
}
# app/index.ts

new Vue({render: h => h(AppComponent)}).$mount('#app')
# app/components/app.component.ts
@Component({ template: require('./app.component.html') }
export default class AppComponent extends Vue {}

It's worth noting that I do not employ .vue, and the error stems from utilizing

@Component({ template: require('./app.component.html') }
.

Is there a workaround for separating files without relying on template, or can I leverage the compiler-included build?

Answer №1

Implementing the runtimeCompiler option worked in my case. However, it is worth noting that it is not essential as the package vue-template-compiler comes pre-installed. Below is a code snippet that shows how to use this option by expanding into a render() function:

import { compileToFunctions } from 'vue-template-compiler'

component: Vue.component("Hola", {
  ...compileToFunctions('<div>Hello user number {{ 1 + 1 }}</div>')
})

Answer №2

While researching Vue.js, I stumbled upon a specific segment in the Vue documentation. In this section titled "Runtime-Compiler-vs-Runtime-only", they provide detailed instructions on what needs to be included for each type of build system.

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

Angular - Unable to access property '$invalid' because it is null

Working on my login page with angular and typescript. Clicking the submit button should trigger the login function in the controller, but if the form is invalid, it should just return. New to typescript, I keep running into an error when trying to add an ...

Is it possible to display two menus on opposite sides of the screen while using Google Maps?

Currently, I am working on developing a Progressive Web App using Vue.js and Vuetify.js. My goal is to have two buttons overlaid on Google Maps - one on the left side of the screen to open a navigation drawer, and another on the right side to display user ...

What is the process for creating a unique Vee-Validate rule in TypeScript?

I am in the process of developing a unique VeeValidate rule for my VueJS component written in TypeScript. This rule is designed to validate two fields simultaneously, following the guidelines outlined in VeeValidate - Cross Field Validation. Here is a snip ...

The resurgence of React JS in its role as a powerful tool

Although I struggle with React JS, I couldn't find a solution for this particular issue. I'm trying to incorporate this function into my tsx file and display it on the screen within a component. function displayUsers() { const UserListComponent ...

Error in Nuxt with Octoin-vue: identifier not recognized

For my project written in nuxt.js, I wanted to incorporate icons from Octicon. To achieve this, I decided to utilize the Octicon Component for Vue.js available here. I created a file named octicon.js and placed it in the /plugins directory, then registere ...

A guide to seamlessly integrating Vue.js directives within custom Django template tags

One of the challenges I encountered in Django was creating a custom template tag named text_field @register.inclusion_tag('form_field_tags/text_field.html') def text_field(field, prefix=None, field_type=None, attr=None, **kwargs): return { ...

Is there a way to trigger the vue-cli build command automatically when specific files are modified?

One way I can build my JavaScript file is by using the following command: vue build main.js --dist dist --prod --lib While this works, I am looking for a way to automate this process whenever I make changes to my JS or Vue files. I prefer not to rely on ...

Selecting the checkbox to populate the input field

In my application, there is an input field that can be filled either by searching for an item or by clicking on a checkbox. When the user clicks on the checkbox, the input should be automatically filled with the default value valueText. How can I detect ...

Guide to creating a unit test for canActivate guard in Angular routing

Seeking guidance on writing a unit test for angular routing with the canActivate guard. Encountering an error when using the guard on routes, but no error is thrown without it. Would appreciate a suitable example along with an explanation. app-routing.mod ...

Retrieve a distinct property of an element from an array of objects fetched from an API using Vue 2

I successfully retrieved an array of objects from an API in mounted within Vue. The array consists of various objects with properties such as author, genre, poster, title, and year. 0: author: (...) genre: ("Rock") poster: (...) title: (...) year: (...) 1 ...

Implementing multi-select checkbox feature in Angular 7 using ng-select

I'm looking to create a function where selecting an item will make the corresponding div appear. For instance, if I choose Crédit bancaire and Compte courant associé, the two corresponding divs should be shown. Check out this example: https://stac ...

Vue: monitoring the 'value' of a v-model within a component

I have a component with a v-model directive that looks like this: <my-component v-model="someData.someProp"></my-component> My goal is to watch this specific piece of data within the component and make adjustments based on any change ...

Issues with string manipulation functionalities in an electron application

Within my electron app, there is a .js file that utilizes the quasar framework. Within this file, I am using axios to request data from my API and process it once the response is received. However, I am encountering issues with string manipulation functio ...

``Incorporating event and parameter as arguments for a function in an Angular application: a tutorial

I am trying to incorporate a checkbox in Angular where if it is enabled, the event.target.checked value is true, and if it is disabled, the event.target.checked value is false. When clicking the checkbox, I need to call a function where I want to pass the ...

Choosing the parent and child elements in order to locate the specific span

I am attempting to display a telephone number when a button is clicked. While hiding the button works perfectly, I am encountering issues when trying to show the phone number by selecting the span from the currentTarget. I have attempted the following code ...

TypeScript combined with Vue 3: Uncaught ReferenceError - variable has not been declared

At the start of my <script>, I define a variable with type any. Later on, within the same script, I reference this variable in one of my methods. Strangely, although my IDE does not raise any complaints, a runtime error occurs in my console: Referenc ...

Guide to using normalize.css via npm installation with webpack

Currently, I am utilizing webpack in conjunction with ReactJS and am exploring the implementation of normalize.css after installing it via npm (). Does the normalize.css take effect immediately upon npm installation? If I were to make modifications to it, ...

I am in the process of transitioning my JSX website to TSX and am struggling to figure out the proper placement of my type definitions

As the title suggests, I am in the process of migrating an application that I developed using the Google Maps API for rendering maps. In this app, I display information on maps and include functionality to zoom in when a user clicks on something. The erro ...

Expanding Mongoose Schema with Typescript: A Comprehensive Guide

Currently, I am in the process of creating 3 schemas (article, comment, user) and models that share some common fields. For your information, my current setup involves using mongoose and typescript. Mongoose v6.1.4 Node.js v16.13.1 TypeScript v4.4.3 Eac ...

Tips for using map on an array to create and return an object with the help of tslint and its syntactic sugar

This is a straightforward question about code style. How do I use the map function to iterate over an array and return a new object without triggering TSLint warnings? TSLint suggests simplifying the arrow function by removing curly braces, 'retur ...