Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Errors Caused by vitest Configuration in Vue App Build #353

Open
MooseSaeed opened this issue Mar 27, 2024 · 6 comments
Open

Comments

@MooseSaeed
Copy link

MooseSaeed commented Mar 27, 2024

Issue Description:

Encountering TypeScript errors related to the vue-router/auto when building a fresh Vue 3 application created with npm create vue@latest. The errors occur specifically with the createRouter and createWebHistory functions.

Steps to Reproduce:

  1. Create a fresh Vue app using npm create vue@latest with the below configuration.
Screenshot 2024-03-27 at 8 18 59 PM
  1. Install and configure unplugin-vue-router.
  2. Run npm run build.
  3. Observe the TypeScript errors in the terminal.

Expected Behavior:

The Vue application should build successfully without any TypeScript errors related to the vue-router/auto.

Actual Behavior:

Encountering TypeScript errors

src/router/index.ts:1:10 - error TS2305: Module '"vue-router/auto"' has no exported member 'createRouter'.

1 import { createRouter, createWebHistory } from 'vue-router/auto'
           ~~~~~~~~~~~~

src/router/index.ts:1:24 - error TS2305: Module '"vue-router/auto"' has no exported member 'createWebHistory'.

1 import { createRouter, createWebHistory } from 'vue-router/auto'
                         ~~~~~~~~~~~~~~~~

Additional Context:

The errors are resolved by removing the path configuration for Vitest from tsconfig.json, which was added automatically during the creation of the Vue app.

    {
      "path": "./tsconfig.vitest.json"
    }

Reproduction Repository:

A reproduction of the issue has been created at: MooseSaeed/tsc-error

@MooseSaeed MooseSaeed changed the title The default tsconfig.vitest.json breaks vue-router/auto TypeScript Errors Caused by vitest Configuration in Vue App Build Mar 27, 2024
@posva
Copy link
Owner

posva commented Mar 27, 2024

I’m interested in the resolution of this config issue to add it to docs but it doesn’t seem to be about the code, just a config issue

@MartinX3
Copy link

MartinX3 commented Apr 2, 2024

I can confirm this issue with Quasar (based on vue3), but I don't use vitest.

@94726
Copy link

94726 commented Apr 5, 2024

I was able to make the npm create vue@latest work by adding
/// <reference types="unplugin-vue-router/client" /> to env.d.ts instead of using the compilerOptions.types inside tsconfig
e.g.

/// <reference types="vite/client" />
/// <reference types="unplugin-vue-router/client" />

@alokVishu
Copy link

I'm experiencing the same issue in Vue.js and Vite projects. Has anyone found a solution?

@jonaaldas
Copy link

Does anybody have a solution for this? I am still having problems and the solutions listed do not work.

@ultimateshadsform
Copy link

ultimateshadsform commented May 2, 2024

For some reason this has stopped working and is generating errors but works fine in browser:

image

image

It doesn't generate needed types for some reason.

Edit: Fixed by downgrading to "unplugin-vue-router": "^0.7.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants