"Encountering issues with importing Splitpanes while using VueJs and TypeScript combination

My VueJS view was originally written in JavaScript using the component "splitpanes" from npm package. The code was functioning well with the following structure:

<template>
 <div>
  <Splitpanes :dbl-click-splitter="false" :horizontal="horizontal">
   <Pane id="pane-video" class="d-flex flex-column">
    ...
   </Pane>
  </Splitpanes>
 </div>
</template>
<script>
import Vue from "vue";
import { Splitpanes, Pane } from "splitpanes";
import "splitpanes/dist/splitpanes.css";
export default Vue.extend({
  components: {
    Splitpanes,
    Pane
  },
...
</script>

I decided to switch the code to TypeScript like so:

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import Splitpanes from "splitpanes";
import Pane from "splitpanes";
@Component({
  components: { Splitpanes, Pane }
})
export default class VideoConf extends Vue {

Upon making this change, I encountered an error message in VS Code:

Could not find a declaration file for module 'splitpanes'. 'client-vue/node_modules/splitpanes/dist/splitpanes.common.js' implicitly has an 'any' type. Try npm install @types/splitpanes if it exists or add a new declaration (.d.ts) file containing declare module 'splitpanes';Vetur(7016)

I attempted both solutions provided: npm install @types/splitpanes and creating a shims-splitpanes.d.ts file with "declare module 'splitpanes'". Although the syntax checking error disappeared in VS Code and I could run npm run serve, upon opening the page in the browser, I received:

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. (and the same error for Pane).

When hovering over the import statement for "splitpanes":

import Splitpanes from "splitpanes"; 

I noticed that it was pointing to the @types folder in node_modules:

module "/Users/lisandro/tmp/aws-chime/client-vue/node_modules/@types/splitpanes/index"

It seems I may be missing something crucial related to @types functionality in a TypeScript project. Any insights or suggestions would be greatly appreciated. Thank you!

Answer №1

After troubleshooting, I was able to resolve my issues by eliminating @types/splitpanes and opting for the subsequent type declaration instead (utilizing the updated splitpanes package).

splitpanes.d.ts:

declare module 'splitpanes' {
    let Splitpanes : any;
    let Pane : any;

    export { Splitpanes, Pane }
}

For instance, here is the sample code from App.vue (demonstrating v-model functionalities):

<template>
    <splitpanes class="default-theme">
        <pane min-size="25">
            <input type="text" v-model="text" />
        </pane>
        <pane min-size="35">
            <p>"{{ text }}"</p>
        </pane>
    </splitpanes>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { Splitpanes, Pane } from 'splitpanes';
import 'splitpanes/dist/splitpanes.css';

@Component({
    components: {
        Splitpanes,
        Pane
    }
})
export default class App extends Vue {
    text : string = "";
}
</script>

<style>
.splitpanes {
    height: 5em;
}
.splitpanes__pane {
    text-align: center;
}
</style>

Additionally, I'll include a simplified version of the tsconfig.json file below (adapted from the Vue.js documentation):

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "strict": true,
        "moduleResolution": "node",
        "experimentalDecorators": true
    }
}

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

There seems to be an issue with the Angular zone.js and zone-evergreen.js files showing an error that reads:

My Angular 11 app suddenly started showing errors across all browsers and environments (local, staging, prod) about an hour ago without any updates: Uncaught TypeError: t.getElementsByTagName is not a function at computeStackTrace.js:338 at Array.f ...

Show image using Typescript model in Angular application

In my Angular (v8) project, I have a profile page where I typically display the user's photo using the following method: <img class="profile-user-img" src="./DemoController/GetPhoto?Id={{rec.Id}}" /> However, I am considering an alternative ap ...

What is the best way to combine TypeScript output while maintaining node import integrity?

Currently, I am combining the results of the typescript compiler using this particular technique. However, this process is causing issues with the imports of relative path modules in Node. The code below compiles and merges successfully; // Group.ts clas ...

typescript page objects in protractor are showing an undefined property

Hey there, I'm facing an issue while using POM in Protractor with TypeScript in Angular CLI. The error I'm encountering is "Cannot read property 'sendUsername' of undefined". Since I'm new to TypeScript, can someone guide me on how ...

Is there a way to include values in the body of an HTTP GET request using Angular?

I've created a function in my service that looks like this: /** * Retrieve all data * @param sendSelectedValues string */ getAllActPlanBalanceYearData(sendSelectedValues: any): Observable<any> { const url = `/yearlyvalues/act-and ...

What is the best way to target a child element within a component's parent?

Within the structure of my project, I have a component with a template set up as follows: <template> <div class="referenceparent"> <input v-model="searchterm" type="text" @input="Search" ...

Retrieve the data of the current component from the slot template

This specific vue component showcases a CardGroup template with a headerRight slot. The content of the slot includes a message displaying the total number of items, accessed through the this.total data property. <template> <CardGroup> ...

Is it possible to utilize a variable for binding, incorporate it in a condition, and then return the variable, all while

There are times when I bind a variable, use it to check a condition, and then return it based on the result. const val = getAttribute(svgEl, "fill"); if (val) { return convertColorToTgml(val); } const ancestorVal = svgAncestorValue(svgEl, "fill"); if (a ...

Is there a way I can keep my ChartJS constantly updated in real time? Currently, it only seems to update when I zoom in or out

I'm looking to create a dynamic graph that updates every 5 seconds or in real-time. I've managed to get it working when zooming in and out of the page, but not when doing nothing. I know it's possible to achieve this, but I can't seem t ...

Running the `npm start` command in Angular tends to be quite time-consuming

When I use Visual Studio Code to run Angular projects, my laptop seems to take a longer time when running the server through npm start compared to others. Could this delay be related to my PC specifications, or is there something I can do to improve it? ...

Send a function as a parameter to another component, but it remains dormant

I am attempting to control the enable and disable state of a button based on changes in a value. To achieve this, I have defined a model as follows: export class Model{ label:string=''; isEnabled:Function=()=>true; } The component1 i ...

Sharing precise API information between React components in React Components

I am currently learning react and facing an issue with sending data to other component files. I am trying to verify a user login from a backend API within an if statement, and if successful, I want to send the user ID to another component file. However, ...

What seems to be the issue with the useState hook in my React application - is it not functioning as

Currently, I am engrossed in a project where I am crafting a Select component using a newfound design pattern. The execution looks flawless, but there seems to be an issue as the useState function doesn't seem to be functioning properly. As a newcomer ...

Error: The promise was not caught due to a network issue, resulting in a creation error

I'm trying to use Axios for API communication and I keep encountering this error. Despite researching online and attempting various solutions, I am still unable to resolve the problem. Can someone please assist me? All I want is to be able to click on ...

Ensure that the date range picker consistently shows dates in a sequential order

Currently utilizing the vuetify date range picker component https://i.stack.imgur.com/s5s19.png At this moment, it is showcasing https://i.stack.imgur.com/GgTgP.png I am looking to enforce a specific display format, always showing the lesser date first ...

Changing a button's text in Vue.js when holding a keyboard modifier - how to do it!

While working with Vue, I am attempting to modify a button's behavior when the Shift key is pressed. Adjusting the behavior of the click event was straightforward: @click.exact="goForward" @click.shift="goBackward" However, I am f ...

Using parseFloat in JavaScript for German number formatting

Currently, I am working on incorporating a Vue.js component that is inspired by the example provided in this link: https://jsfiddle.net/mani04/bgzhw68m/. This is the structure of my source code: computed: { displayValue: { get ...

An error in npm occurred: "The name "@types/handlebars" is invalid."

While attempting to install typedoc using npm, I encountered the following error: npm ERR! Invalid name: "@types/handlebars" To resolve this issue, I proceeded to install @types/handlebars directly by running: npm install @types/handlebars However, I r ...

Using vuexfire's firestoreAction to bind with a specific argument is a powerful

I'm attempting to connect my module's store to a document import Vue from 'vue' import { db } from '../my-firebase/db' import { firestoreAction } from 'vuexfire' export const user = { ... actions: { ...

What methods are available to me for creating a wrapper for an Angular Component that simply changes the component selector name?

Having experience with React, you can simplify a library component in your app by giving it a new name like this: const MyAppTable = (props) => <LibraryTable ...props />; I'm interested in achieving a similar result in Angular, but I'm ...