A basic Vue component shows error message "SyntaxError: import not found: default"

I seem to be facing an issue while breaking down some large components into smaller ones. One of the new components I created appears mostly empty:

<div>
  test
</div>

<script>
  export default {
    data() {}
  }
</script>

In my parent component, I include this new component using <my-new-component /> (which works fine with all other components).

In the script tag of the parent component, I have the following code:

import MyNewComponent from "path"; // everything seems correct when checking in the IDE

export default {
  components: {
    MyNewComponent
  }
}

However, I keep encountering the error message

Uncaught SyntaxError: import not found: default
within the MyNewComponent.vue file.

This is the same setup I use for all my other components. What could I possibly be missing? I am working on Vue 2.7

Answer №1

To properly structure your HTML code, enclose it within a template tag.

<template>
  <section>
    example content
  </section>
</template>

<script>
  export default {
    data() {}
  }
</script>

Answer №2

The problem was resolved when the OP wrapped the divs inside a template tag as shown below:

<template>
  <div>
    test
  </div>
</template>

<script>
export default {
  data() {
    return {
      // impressive code here
    }
  }
}
</script>

For further reference, check out this link on why it's important for data to be returned as a function.

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

What is the best way to display label information on a Google line chart?

line graph column graph My graph continuously calls the Controller to fetch recent data from the Database. There are two lines on the graph, and I would like to display the names of each line (column) such as red=counts of something // brown=counts of so ...

Adjust the position of the element by lifting it slightly

I am looking to adjust the positioning of the number "01 / 04" to match the layout shown in this image: https://i.sstatic.net/3MNA5.png Here is what I have accomplished so far: https://i.sstatic.net/6ayOx.jpg This is how the code structure looks like i ...

Obtain cell information when clicking on a specific field within a material-table

import MaterialTable from "material-table"; import ShipmentContext from "../context/ShipmentContext"; const ItemsTable: React.FC = () => { const shipmentcontext = useContext(ShipmentContext); const { filtered } = shipmentcontex ...

Dealing with file upload dialog using Selenium web automation

I am having difficulty managing the 'select files to load' dialog using Selenium WebDriver. Here is the HTML code snippet: <form class="upload"> <button class="btn" data-capture="" type="button">Browse</button> <inpu ...

The functionality of the Google Analytics pageTracker function is hindered when it is loaded through AJAX requests

After previously discussing this issue, I have conducted further research and attempted to resolve the problem, but unfortunately, a solution still eludes me... My website (www.seatgeek.com) incorporates numerous links that are loaded via AJAX. Whenever a ...

Activate function upon closure of window.open

I'm facing an issue where I need to load a URL in window.open that saves some cookies in my browser. After the window.open is closed, I want to access those cookies but I haven't been able to find a way to do it. I've tried the following cod ...

Incorporating native JavaScript classes within an Angular application

I have created a custom JavaScript class: var ExampleClass = new function(elements) { this.elements = elements; this.someFunction() { // logic involving this.elements }; }; How can I incorporate it into an A ...

TypeError: The firestore function within the firebase_app__WEBPACK_IMPORTED_MODULE_0__ object is not recognized in Vue.js

I encountered a problem with my firebase.js file where I received the error message Uncaught TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0__.firestore is not a function in my console. Despite trying different methods to import firebase, none of them ...

Creating a three.js lathe object using SVG spline with a Bézier curve

For my new game project, I am currently designing a replica of the iconic theme building located at LAX airport. I am exploring methods to transform an svg spline (featuring Bézier curves) into a lathe object within three.js. Is there a reliable way to a ...

React does not accept objects as valid children. If you want to render a group of children, make sure to use an array instead

I am in the process of developing a system for document verification using ReactJS and solidity smart contract. My goal is to showcase the outcome of the get().call() method from my smart contract on the frontend, either through a popup or simply as text d ...

The outcome of a function within the $.ajax method is transformed into a string

Trying to pass an array of IDs using the $.ajax data variable is proving to be a challenge. The array is generated by a function, and I've noticed that if I define this function outside of the $.ajax call, it works fine. However, when I place the same ...

"Is there a way to automatically delete items from a v-for loop after a

Can someone advise me on the best way to add, remove, and restart a timer for a messaging feature? The goal is to automatically delete messages 5 seconds after they are sent, but pause the deletion if the user hovers over the message. Messaging Code & ...

Best practices for organizing a Vue/Node application when integrating the Instagram API

I have a project that involves connecting to the Instagram API, retrieving user data, and displaying it within the application. The functionality of my application is such that when a user clicks on a "connect" button on a page, they are connected to the ...

The contrast between FormData and jQuery's serialize() method: Exploring the distinctions

Recently I came across a situation where I needed to submit a form using AJAX. While researching the most efficient method, I discovered two popular approaches - some developers were utilizing jQuery#serialize() while others were opting for FormData. Here ...

Increase the lag time for the execution of the on('data') function in Node.js

In my current function, it searches data from a database and performs an action with it. For the purpose of this demonstration, it simply increments a counter. exports.fullThreads = function(){ return new Promise((resolve, reject) => { MongoClien ...

Developing a project similar to the one designed for three.js

I'm excited about recreating something similar to the example in this video: http://www.youtube.com/watch?v=gYGzsM4snmg. Can anyone provide guidance on where to find the source code or offer a beginner-friendly explanation, considering I am new to thr ...

Ways to verify the $window variable in ng-if or ng-show

One variable named variable1 has been declared, and I am looking to validate this variable across all pages using ng-if or ng-show. ...

Guide on transferring binary image data to a JavaScript function

I have $comment->image_data as the binary data of the image and I want to pass this data to the imgclick() function. Attempting the method below, but encountering an unexpected token error. <img src="data:image/jpg;base64,'.$comment->image_t ...

What methods can I use to integrate Cheerio with CSS Manipulation?

I've been working on a web scraping project using axios, cheerio, and express. However, every time I attempt to run the project, it encounters errors. For testing purposes, I am using a test page from my friend's website. Here is the code snippe ...

Transmit information back to ASP.NET using AngularJS

As a newcomer to coding, I have a question. I am retrieving data from my database using C# and AngularJS, modifying it, and then sending it back. Eventually, I will need to save the modified data in the database. Here is my code, thank you in advance. The ...