Vite and Vue3 Error: An unexpected ">" was encountered instead of "setup" while using the "ts" language attribute

While executing the command vite build, the build process fails with the error message

Expected ">" but found "setup"
. Surprisingly, this issue even occurs when using the default HelloWorld.vue component (which is included in the Vite + Vue TS sample project).

<!-- Badge.vue -->

<script setup lang="ts">
console.log("help me")
</script>

<template>
Irrelevant
</template>
// vite.config.ts

import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [vue()],
    build: {
        rollupOptions: {
            input: {
                ["main"]: "src/main.ts",

                // Add new pages here
                ["pages/Badge"]: "src/pages/Badge.vue",
            },
            output: {
                entryFileNames: "[name].mjs",
                chunkFileNames: "[name].mjs",
                assetFileNames: "assets/[name].[ext]",
            }
        }
    }
})

The error can be avoided if:

  • There is no content between the <script> tags (absolutely nothing, not even comments)
  • The lang="ts" part is omitted

I have attempted to change the order of attributes in the <script> tag (i.e.

<script lang="ts" setup>
), but it results in the same error message in reverse (Expected ">" but found "lang")

Answer №1

After some investigation, I was able to pinpoint the issue to the vite.config.ts file. To resolve this problem for others facing it down the road, all that was needed was to delete any instances of .vue files from the build.rollupOptions.input section.

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

How can one locate exclusively unused JSDoc type definitions?

For instance: /** * A boolean value. * @typedef {boolean} BoolType * * Another dummy type definition. * @typedef {(number|string)} SomeType */ /** * Set the boolean flag. * @param {BoolType} flag - The bool flag value. */ function setFlag(flag) { ...

Ways to transfer specific properties from one object to another in TypeScript

I'm currently working on a function that selectively copies key-value pairs from one object to another in order to remove certain properties. The code snippet for this function is shown below: sanitizeData: function (sourceObject: object, ...allowedKe ...

Node.js is raising an error because it cannot locate the specified module, even though the path

Currently in the process of developing my own npm package, I decided to create a separate project for testing purposes. This package is being built in typescript and consists of a main file along with several additional module files. In the main file, I ha ...

Using solely the directory to import index.ts

When attempting to import a module called index.ts from a directory by only specifying the directory name and not the module name itself, I encountered a TS2307 error stating "Cannot find module". Here is a snippet from ./src/main.ts: 'use strict&ap ...

Issue: The function "MyDocument.getInitialProps()" needs to return an object containing an "html" prop with a properly formatted HTML string

Check out my project on GitHub at https://github.com/Talita1996/NLW4 To start the project, I used the command yarn create next-app project_name I made changes to some files by modifying their extensions and adding new code Next, I added typescript to the ...

How can a loading indicator be displayed while retrieving data from the database using a prop in a tabulator?

Incorporating a tabulator component into my vue app, I have set up the Tabulator options data and columns to be passed via props like this: // parent component <template> <div> <Tabulator :table-data="materialsData" :ta ...

Classify Express v4 router as a class

Despite successful compilation and the server supposedly starting on the correct port, I encounter a "cannot access this route" error when attempting any of my registered routes. I've come up short in finding resources on using express with classes, ...

I encountered an issue when trying to call a class in angular 2, receiving the error message "Supplied parameters do not match any

A new class named items-class.ts was successfully created: export class ItemsClass { constructor(public name:string, public desc:string, public stat:string){} } To implement this class in a component called app.component.ts: import { Component } fro ...

Having trouble fetching configuration values with Vue.js

console.log(process.env.test); displays "undefined" in the console. In the dev.env.js file, I have the following configuration. Do you see anything that I might have overlooked? 'use strict' const merge = require('webpack-merge') con ...

What are the possibilities of utilizing a variable that is stated within composition to enable dynamic rendering?

I'm working on a Vue.js v3 project using the composition API. I have defined a variable in my setup like this: setup() { const showInvoiceItemForm = true; return { showInvoiceItemForm }; }, Now, I want to show a form when a button is click ...

What is the method for extracting user input from a text box on a webpage?

Having trouble with retrieving the value from a text box in my search function. SearchBar Component import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-search', templateUrl: './search.compon ...

Unable to call Ionic component function using ref in Vue3

I'm attempting to utilize the closeSlidingItems method of the IonList element in order to automatically close the sliding item after clicking a button that appears from behind once the item is slid to the right. My approach involved referencing IonLi ...

Remove an owl carousel using Laravel, Vue.js, and Axios

I've implemented a sleek slider on my website to showcase images with accompanying text to visitors. The slider utilizes owl carousel within a vue component and is functioning properly. Now, I'm attempting to add a delete button so that users who ...

Guide on sending an array of objects to Material Vue Autocomplete

Context Currently, I am dealing with a situation where I am passing an array of objects to a material autocomplete feature. The documentation for this can be found here. However, upon selecting an item from the list for the first time, it throws an error ...

Tips for preventing the vue/require-prop-type-constructor alert in VueJS

A boolean variable isTabsEnabled is being used to control a Tabview and toggle the display of tabs. This property is passed as a child to the screens where it is utilized, within this parent file. export{ props:{ isTabsEnabled: true } } When usin ...

Achieving dynamic serving of static files using Rollup and integrating seamlessly with node-resolve

Currently, I am in the process of building a library using TSDX, which is a powerful CLI tool for package development based on Rollup. My project involves a collection of country flags SVGs that need to be imported and displayed dynamically when required. ...

Utilizing Lodash for Effective Grouping of Arrays of Objects

Here is an example of an array of objects: [ { item: "123", categories: [A,B,C] }, { item: "456", categories: [B,C] }, { item: "789", categories: [C,D,E] } ] I'm exploring usi ...

Using React Native, it is not possible to include headers in a fetch API request

Currently, I am utilizing the Fetch API in react-native along with typescript. The code snippet I am working with looks like this: let responseLogin = await fetch('http://url_example', { method: 'POST', headers: {' ...

Vue.js is throwing a TypeError message stating that it is unable to read the property 'post' of undefined, despite the fact that vue-resource has been successfully

Alright, here's the issue: I'm encountering a TypeError and I can't figure out why. I have Vue-resource installed and imported Vue.use('vue-resource'); import {} from 'vue-resource'; in my main.js file. I've tried ...

Guide to triggering a function upon selecting a row in a SyncFusion grid

My goal is to use a SyncFusion Vue Grid component and trigger a function when a row is selected. I attempted to include a column of edit buttons, but I am struggling to find the correct syntax to make these buttons call a function. Alternatively, I tried ...