Having trouble importing a module or library in VueJS?

After setting up a slider library called Hooper in VueJS 3, I imported it locally like this:

<template>
  <hooper>
    <slide>1</slide>
    <slide>1</slide>
    <slide>1</slide>
    <slide>1</slide>
    <slide>1</slide>
  </hooper>
</template>
<script>
 import { Hooper, Slide } from 'hooper';
 import 'hooper/dist/hooper.css';

 export default {
  components: {
    Hooper, Slide
  }
 }
</script>

I encountered an issue while trying to import hooper (import { Hooper, Slide } from 'hooper'). There are three dots under the word "hooper", indicating:

Could not find a declaration file for module 'hooper'. 'c:/Users/nurdi/pkl/template/java-vibes/node_modules/hooper/dist/hooper.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/hooper` if it exists or add a new declaration (.d.ts) file containing `declare module 'hooper';`Vetur(7016)

In addition, an error appeared on the console stating:

Uncaught TypeError: vue__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor
at eval (hooper.esm.js?7e04:172:1)
at Module../node_modules/hooper/dist/hooper.esm.js (chunk-vendors.js:1393:1)
at __webpack_require__ (app.js:849:30)
at fn (app.js:151:20)
at eval (GuestBook.vue?ed46:64:1)
at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader-v16/dist/index.js?!./src/components/GuestBook.vue?vue&type=script&lang=js (app.js:986:1)
at __webpack_require__ (app.js:849:30)
at fn (app.js:151:20)
at eval (GuestBook.vue?9b66:1:1)
at Module../src/components/GuestBook.vue?vue&type=script&lang=js (app.js:1840:1)

Answer №1

Upon reviewing your file, I have identified several issues that may be causing errors:

  • Could not find a declaration file [..]
    appears to be a Typescript error, likely due to the Vue CLI including TS by default. If you are not using TypeScript, consider changing <script> to
    <script lang="js">
    . It is recommended to make this change regardless.
  • Ensure that you import Vue and update export default {} to export default Vue.extend({}) to indicate that it is a Vue component.
  • The error
    Uncaught TypeError: vue__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor
    suggests that a default import could not be located in the referenced file. This issue may stem from one of the previous two problems or potentially be an internal problem within the library itself.

Please note that my experience lies primarily with Vue 2, so some of these suggestions may not directly translate to Vue 3.

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

Using Array Data Binding in SAPUI5 for Lists

I am looking to connect a list along with its content to a model. var listItem = new sap.m.StandardListItem({ title: "{carDataModel>/cars/1/carId}", }); var list = new sap.m.List("carList", { }); list.bindItems('carDataM ...

Associating the object key and value with distinct attributes within the component

person = {name: 'Alice', age: '19', weight: 52} I'm looking to display both the keys and values from the object in one label and input field respectively. I attempted using Object.entries, but couldn't figure out how to sepa ...

Issue with PeerJs Localhost Setup

Implementing the zoom clone with WebRTC using peerjs, I am facing an issue where myPeer.on("call", (call) => { is not getting called. This code works fine for others on localhost who followed the tutorial on the zoom clone. I am unsure of what ...

Hovering over the Laravel Breeze dropdown will activate a dropdown feature

Recently, I've been working on a project with Laravel Breeze and have been utilizing some default components. The dropdown component used in the navigation bar caught my attention. By default, it requires a click for the menu to drop down below. Howev ...

"Exploring the power of Node.js by utilizing ObjectArray and implementing

Can I compare two arrays of objects in JavaScript? My goal is to find the common objects between these two arrays: First object array: [ { id_0: 356, name_0: 'xxxxx', id_1: 33, name_1: 'yyyyyy', id_ ...

Tips on how to efficiently update or insert an object within an array in Vue JS 2

My current item list is displayed below. I am looking to add new items to the list, but if the ID matches an existing entry, I want to update the value of that object. For example: segmentValues: [ { id:1, value:'Foo' }, ...

Which architectural style is best to master for developing exceptional JavaScript software?

My familiarity with Model-View-Controller runs deep, having worked with it for years in server-side development using languages like PHP. Now, I find myself diving into JavaScript and embarking on a large project that utilizes SVG, Canvas, and other moder ...

Clicking the submit button in JavaScript will trigger a request to the Spring MVC backend,

When I use the following code, it gives me an object response: @RequestMapping(value = "/NewLogin",method = RequestMethod.POST) public @ResponseBody Token getAllBooks( Token token = new Token(); token.setValue(encryptedMessage); return toke ...

The issue arises with proptypes validation while implementing material-ui components

Just embarked on a new ReactJS project and ran into a plethora of errors when I integrated material-ui. One of the errors looked like this: bundle.js:12441 Warning: Failed Context Types: Calling PropTypes validators directly is not supported by the prop ...

call a custom form submission using jquery first, followed by a regular form submission

Is it possible to attach a submit() handler to a form in order to execute an ajax request, and then have the form submit itself normally once the request is complete? Using $('#myForm').submit() seems to just result in the same function being cal ...

Show SVG in its ViewBox dimensions

Currently, I am utilizing the img-Tag to showcase SVG images that have been uploaded by users onto my Amazon S3 storage. <img src="http://testbucket.s3.amazonaws.com/mysvg.svg" /> An issue arises once the image is displayed as it does not retain i ...

Having trouble sending data to a Django function with Ajax request

I am currently facing an issue with my AJAX calls in Django. While fetching data works seamlessly, adding new data is resulting in an error message. Method Not Allowed (POST): /mymodels/ Method Not Allowed: /mymodels/ [17/Mar/2020 22:27:24] "POST /mymodel ...

The creation of transparent objects in THREE.js allows for a dynamic display of overlaid objects in the

Greetings, I am interested in creating a three.js room where the walls behind which objects are located (from the perspective of the camera) will become transparent with 50% opacity as I rotate the room. Allow me to elaborate: Visualize a scenario whe ...

Ensuring Consistent Item Widths in a Loop using JavaScript or jQuery

In my code, I created a function that dynamically adjusts the width of elements in a loop to match the widest element among them. // Function: Match width var _so20170704_match_width = function( item ) { var max_item_width = 0; item.each(function ...

Issue with Vuex getter not reflecting correct value after modifying an array

I've been delving into the world of vuex, and I'm currently working on fetching the count or an array when I make additions or removals. Below, you'll find the code snippets I'm working with. home.vue template <template> < ...

Repeatedly triggering the Jquery Dialog Event

When I open a calendar plugin in jquery dialog, I encounter a recurring issue. Every time I close and reopen the dialog, my calendar event onDayClick triggers multiple times – twice, thrice, and so on. <div id="show_calendar"> <div class="c ...

Mongoose virtual population allows you to fetch related fields

When attempting to utilize virtual populate between two models that I've created, the goal is to retrieve all reviews with the tour id and display them alongside the corresponding tour. This is achieved by using query findById() to specifically show o ...

A guide on invoking a servlet using a jQuery $.ajax() call

I am having trouble calling a servlet using jQuery's .ajax() function. It seems like the servlet is not being called or parameters are not being passed to it. Despite searching extensively online, I have not been able to find a solution. Any suggesti ...

unable to adjust the maximum height limit

I've been struggling to set a maximum height on the slider I'm currently using. No matter what height value I input, it doesn't seem to take effect. Additionally, I attempted setting the width for the echo img row in the PHP section but enco ...

What is the best way to ensure that messages stay saved in my app for an extended

I am looking for a way to store messages sent through my small messaging app in a persistent manner. Currently, the messages are transferred from the front-end to a Node, Socket.io, and Express back-end. A friend recommended using Enmaps (), but unfortuna ...