Encountering an Uncaught Exception while trying to import a Vue component onto my website

I am facing an issue on my page where I am loading certain JavaScript files. The files being loaded are:

  • Vue.js
  • app.js

The app.js file has been compiled using webpack and includes a NPM component from @chenfengyuan/vue-countdown.

My goal is to display a Vue.js countdown component on the page by using the following code snippet:

<div class="container" id="app">
  <vue-countdown :time="2 * 24 * 60 * 60 * 1000" v-slot="{ days, hours, minutes, seconds }">
    Time Remaining: @{{ days }} days, @{{ hours }} hours, @{{ minutes }} minutes, @{{ seconds }} seconds.
  </vue-countdown>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="js/app.js"></script>
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script>
  import VueCountdown from '@chenfengyuan/vue-countdown';

  // Vue application
  const app = new Vue({
    el: '#app',
    data: {
      messages: [],
    },
  });
  app.component(VueCountdown.name, VueCountdown);
</script>

Upon running this code, I encounter a JavaScript error that states:

Uncaught SyntaxError: Cannot use import statement outside a module

I need assistance in understanding what mistake I have made and how I can rectify it for correct importing of the module.

Answer №1

You don't have to worry about imports since referencing the script will automatically add it to the page scope. Feel free to check out my codepen example here.

The issue you encountered was likely due to not including components, but you were very close!

<div class="container" id="app">
  <vue-countdown :time="2 * 24 * 60 * 60 * 1000" v-slot="{ days, hours, minutes, seconds }">
    Time Remaining:@{{ days }} days, @{{ hours }} hours, @{{ minutes }} minutes, @{{ seconds }} seconds.
  </vue-countdown>
</div>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@chenfengyuan/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ceae9f9b1fff3e9f2e8f8f3ebf2dcadb2adb2a9">[email protected]</a>/dist/vue-countdown.min.js"></script>

<script>
  const app = new Vue({
    el: '#app',
    components: {
      VueCountdown,
    },
    data: {
      messages: [],
    },
  });
  // You can ignore this line as it is unnecessary
  // app.component(VueCountdown.name, VueCountdown);
</script>

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

Guide on creating an AngularJS application using Yesod

After successfully developing a small app using Yesod, I am now focused on adding improved interaction to it with the help of AngularJS. Currently, it appears that the AngularJS support in Yesod is still in an experimental phase. Additionally, the documen ...

Converting HTML to PDF using JavaScript

My goal is to create an HTML page and then print and download it locally as a PDF. However, when I try to generate the PDF, it cuts off the last 3 to 4 lines of the page. I want to create multiple PDF pages in A4 size with the same styling as the HTML pa ...

Navigating through the DOM using JavaScript or regular expressions

I have a DOM string called innerHTML and I am looking to extract or display the node value using either JavaScript's DOM API or JavaScript RegEx. "<nobr> <label class="datatable-header-sortable-child" onmousedown="javascript:giveFeedback(&ap ...

Issue encountered while rendering tables with Jquery-dataTables

Encountering an issue with jquery datatables when fetching data from a URL using ajax calls. Implementing the codeigniter framework, I utilize the datatables library to create datatable objects by invoking the echo $this->datatables->generate() metho ...

Creating an object in JavaScript using an array type初始化数组类型为对象javascript

In my code, there is an interface defined as Products export interface Products{ category: string; imageUrl: string; price: number; title: string; } Within my component, I have a variable named products which is an array of type Product ...

Circular Dependencies Among Vue Components

I have developed two components (A and B). I am attempting to create a recursive loop between them. CompA invokes CompB, CompB invokes CompA, and so on: Page -> CompA -> CompB -> CompA -> CompB -> ... This is the content of CompA.Vue <Co ...

What is the best way to display a jQuery UI dialog when the page is reloaded?

I am trying to display a jQuery UI dialog when the user tries to reload or close the browser. Here is my code snippet: $(window).bind('beforeunload', function () { $("#confirm").dialog({ width: 500, modal: true, buttons: { ...

Is there a way to retrieve the value of a particular attribute while hovering the mouse over it?

When I hover my mouse over the innerHTML content, certain words are highlighted with a title attribute value. How can I retrieve the specific title value of the content I am hovering over? This should be done using the mouseover event in the TypeScript fil ...

Tips for Developing Drag Attribute Directive in Angular 2.0

Currently, I am referencing the Angular documentation to create an attribute directive for drag functionality. However, it seems that the ondrag event is not functioning as expected. Interestingly, the mouseenter and mouseleave events are working fine ac ...

Error occurs during server to server mutation with Apollo Client (query successful)

Currently, I am using apollo-client on my web server to interact with my graphql server (which is also apollo). While I have successfully implemented a query that retrieves data correctly, I encounter new ApolloError messages when attempting a mutation. Od ...

Error: Property 'barcodeScanner' is not readable

Currently, I am utilizing barcodescanner.js for scanning QR codes. I have successfully downloaded and linked the CaptureActivity android library to my project. However, when attempting to execute the following code: window.plugins.barcodeScanner.scan(sca ...

Utilize Express and Mongodb to interact with API and database queries

Looking for assistance with my project on creating a gaming server list. Users should be able to add their server by entering a title, IP, port, and some information about it. However, on the homepage, I also want to display the number of players and whet ...

How can I import a component directly from a webpack bundle in React?

Under normal circumstances, components are imported from another JavaScript file. However, in my project, I am looking to import a component from the webpack-created bundle. Step 1: Generate a bundle for the ABC folder, naming it abc.bundle.js Note: The ...

Incorporating traditional Javascript classes for modeling in React development

Can traditional JavaScript classes be utilized in models within the MVC framework while using React, as opposed to relying on Redux or contexts & reducers which may impact reusability? If this approach is feasible, how can we efficiently 'subscribe&ap ...

The issue with Framer motion's whileInView is that it does not animate the element when it is within the viewport in Next.js

In my current Next.js 14 project with the App Router, I decided to play around with animations using Framer Motion. One specific feature I wanted to implement was animating text elements into view as they enter the viewport. The idea is for the text to gra ...

Obtain the complete path in Vue router by utilizing nested routes

After creating nested routes for Vue Router, I encountered a problem while using the routes to generate a navigation menu. Currently, I am using route.path in 'router-link :to=' which only gives me a part of the path. I want to include the absolu ...

Utilizing Angular RXJS to generate an array consisting of three different observable streams

I am trying to use three different streams to create an array of each one. For example: [homePage, mainNavigation, loan_originators] However, currently only mainNavigation is being returned. const homePage = this.flamelinkService.getData('homePage ...

Is there a way to apply toggling and styles to only the card that was clicked in Vue.js?

DisplayBooks.vue consists of a single page responsible for showcasing books fetched from a backend API. Each card on the UI features two buttons - ADD TO BAG and ADDED TO BAG. When a user clicks on the ADD TO BAG button of a specific card, it should toggle ...

Converting a comma-separated string into an array of integers using jQuery

Is there a way in jQuery to convert a string containing multiple numbers into an array? The string in question is as follows: let values = "901,235,342,421,345,745,544,324,445,123,232,986,345,678"; ...

Jquery Validation Plugin - Specifically for validating numeric inputs in specific situations

I am currently working on implementing validation using jQuery Validate for a numeric value, but only when a specific radio button is checked. If the radio button is not checked, the field should be required and allow alphanumeric values to be entered. How ...