Why is vue-tsc searching for Vue Test Utils types in my custom types file instead?

My current project is using Vite, Vue3, TypeScript, and Jest for testing purposes.

Within my project, there is a Vue component named Btn.vue, which imports a Variant type from my @/types/index.d.ts. (Please note that the @ alias has been configured in my tsconfig.json, vite.config.js, and

jest.config.js)</p>
<p><strong>Btn.vue</strong></p>
<pre><code><script setup lang="ts">
import { Variant } from '@/types'
// ...the rest of the component
</script>

types/index.d.ts

export type Variant = 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'danger'

The tests for this component are located in an adjacent spec file and all pass successfully.

Btn.spec.ts

import { mount } from '@vue/test-utils'
import Btn from './Btn.vue'

describe('Btn component', () => {
  // ...all the tests
})

However, during the build process using

vue-tsc --noEmit && vite build
, errors occur as shown below:

node_modules/@vue/test-utils/dist/interfaces/wrapperLike.d.ts:1:10 - error TS2305: Module '"src/types"' does not export 'DefinedComponent'.
1 import { DefinedComponent, FindAllComponentsSelector, FindComponentSelector, NameSelector, RefSelector } from 'src/types';
           ~~~~~~~~~~~~~~~~

node_modules/@vue/test-utils/dist/interfaces/wrapperLike.d.ts:1:28 - error TS2305: Module '"src/types"' does not export 'FindAllComponentsSelector'.
1 import { DefinedComponent, FindAllComponentsSelector, FindComponentSelector, NameSelector, RefSelector } from 'src/types';
                             ~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@vue/test-utils/dist/interfaces/wrapperLike.d.ts:1:55 - error TS2305: Module '"src/types"' does not export 'FindComponentSelector'.
1 import { DefinedComponent, FindAllComponentsSelector, FindComponentSelector, NameSelector, RefSelector } from 'src/types';

It appears that vue-tsc is having issues locating the Vue Test Utils types and is mistakenly referring to my custom types file instead.

Answer №1

After receiving a response to my bug report on the Vue Test Utils Github, it has been revealed that the issue is related to relative imports and will be resolved in the upcoming release. At the moment, I am using version ^2.0.0-rc.18, which suggests that the fix might be included in version ^2.0.0-rc.19.

In the interim, I managed to successfully build by adding "skipLibCheck": true, to the compilerOptions within my tsconfig.json file.

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

Pause for a few moments prior to initializing Bootstrap and Angular 2

I am currently developing a space/gravity game using Angular 2, and I am looking to incorporate a splash screen before the main menu component is loaded. I believe that the easiest approach would be to utilize the pre-bootstrapped contents of the index.ht ...

Can Angular be utilized for developing an email application?

Can an email application be developed using Angular? I attempted to incorporate a nodejs script, but encountered issues when using the nodejs script within an Angular TS file, resulting in the following error: Error: Module not found: Error: Can't re ...

What steps can be taken to prioritize files with specific extensions in webpack?

I have a dilemma with two files: - somefile.scss - somefile.scss.ts When importing the file in my typescript code, it is referencing the wrong one: import styles from "somefile.scss" The typescript part works fine with the correct import (.scss ...

Developing a Type-inclusive TypeScript encapsulation for the first level of Array.flat() with generic functionality

I am working on creating a function that constructs an array from the input arguments, allowing for only one type or arrays of that same type. Essentially like (...items)=>items.flat(1), but with type safety and generics. It seems crucial to ensure that ...

The method this.textSize does not exist

I encountered this issue : Uncaught (in promise) TypeError: this.textSize is not a function when using this.textSize. If I just use textSize, it prompts me that it is undefined. Interestingly, these lines of code are located in the same file and appear ...

Guide on generating virtual nodes from a string containing HTML tags using Vue 3

Investigation I stumbled upon this solution for converting a simple SVG with one path layer into Vue2 vnode list and wanted to adapt it for Vue3. After scouring resources, including the MDN docs, I couldn't find any pre-existing solutions. So, I dec ...

Passing a Vue.js variable to a Laravel Eloquent model in a Laravel Blade template file

I attempted to include attribute_id in an Eloquent query, where attribute_id is a variable from Vue.js. However, I encountered the following error: Use of undefined constant attribute_id - assumed 'attribute_id' <div v-for='(attribute_ ...

Webpack 5 is failing to bundle re-exports correctly

Whilst bundling my web application, I've come across an issue with re-exports of certain modules not behaving as expected. Despite trying various optimization settings, I have been unsuccessful in resolving this issue. Setup Here's the setup tha ...

Struggling with the incorporation of Typescript Augmentation into my customized MUI theme

I'm struggling with my custom theme that has additional key/values causing TS errors when I try to use the design tokens in my app. I know I need to use module augmentation to resolve this issue, but I'm confused about where to implement it and h ...

I am having issues with the functionality of vuejs's this.$route

When I send a delete request to the API, it works fine. However, the next step is redirecting to the index page. I tried using this code this.$router.push('/'); but it doesn't seem to be working. index.vue <template> <div cl ...

Ways to display all utilized typescript types within a project

Here is a snippet of code I'm working with in my project: describe('Feature active', () => { it('Should render a Feature', () => { const wrapper = shallow(<MyComponent prop1={1}/>); expect(wrapper.prop('p ...

What would be the most effective approach for creating a reactive setter for an object within an array in Vuex?

I am working with a Vuex object that contains an array of languages consisting of objects with guid, name, and level properties. I am trying to figure out how to write a method that will make it reactive. Currently, I have an input field with a value of " ...

The message "Error: Unknown custom element: <router-view> - have you properly registered the component?" is prompting for a solution

Even though the name is correctly capitalized in all my component instances, I am still encountering an error. After researching similar issues online, it appears that the problem usually revolves around naming discrepancies. However, I have double-checked ...

Enumerations in Typescript act as interfaces

Utilizing a TypeScript to proto file generator library (ts-protoc-gen), results in the generation of the following code snippet for enums: export interface AnimalTypeMap { Dog: 0; Cat: 1; Fish: 2; Bird: 3; } export const AnimalType: Anim ...

The Vue error message is indicating a problem with a missing module: `eslint/lib/ast-utils` that cannot be found

When attempting to execute eslint on my code, I encountered the following error: > vue-cli-service lint; vue-cli-service test ERROR Error: Cannot find module 'eslint/lib/ast-utils' Referenced from: /Users/username/Development/project/tests ...

Having trouble with the 'plugin not installed' error when using ionic-native/network-interface?

After following the official documentation, I am using ionic-native/network-interface to retrieve the IP address of the wifi network I am connected to. However, I am encountering an error stating that the plugin is not installed. Here is the code I have i ...

Can you explain the distinction between using npm init vite@latest versus npm init vite?

I decided to give vite a try for building my react apps after getting frustrated with the slow installation process of create-react-app. However, I've noticed conflicting information online about setting up a vite app. The official documentation recom ...

The ordering of parameters should not impact the functionality of Typescript generics, though currently it does

My mergeArrays generic function is designed to not rely on the order of parameters. However, when it is used within another generic function, the result seems to depend on the order. This unexpected behavior is puzzling. type Fn = (...args: any[]) => an ...

Vue 3 required but not found as a peer dependency

Every time I execute npm list -g --depth=0 command in cmd, npm throws this error. +-- @vue/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086b6461483c263d263e">[email protected]</a> +-- <a href="/cdn-cgi/l/emai ...

Setting references for Vue 3 components once the parent component has been successfully mounted

In my Vue component, I have the following setup: <script setup> // ...imports const entries = ref([]); const entryComponentsRefs = ref([]); onMounted(async () => { entries.value = await fetchEntries() }); </script> <template> &l ...