vite-plugin-dts icon indicating copy to clipboard operation
vite-plugin-dts copied to clipboard

TS-Errors when building with Vite `v5.3.1`

Open razorness opened this issue 1 month ago • 1 comments

Describe the bug

When creating a new project using template vue-ts and using vite-plugin-dts for building a library, you'll get TS errors for external libraries.

user@wsl:/opt/vite-project$ yarn build
vite v5.3.1 building for production...
src/components/HelloWorld.vue:2:21 - error TS2792: Cannot find module 'vue'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

2 import { ref } from 'vue'
                      ~~~~~
src/components/HelloWorld.vue:4:1 - error TS2347: Untyped function calls may not accept type arguments.

4 defineProps<{ msg: string }>()
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/components/HelloWorld.vue:10:10 - error TS2339: Property 'msg' does not exist on type '{}'.

10   <h1>{{ msg }}</h1>
            ~~~
src/components/HelloWorld.vue:13:35 - error TS2339: Property 'count' does not exist on type '{}'.

13     <button type="button" @click="count++">count is {{ count }}</button>
                                     ~~~~~
src/components/HelloWorld.vue:13:56 - error TS2339: Property 'count' does not exist on type '{}'.

13     <button type="button" @click="count++">count is {{ count }}</button>
                                                          ~~~~~
src/main.ts:1:27 - error TS2792: Cannot find module 'vue'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?

1 import { createApp } from 'vue';
                            ~~~~~

✓ 11 modules transformed.

[vite:dts] Start generate declaration files...
dist/style.css  1.27 kB │ gzip: 0.65 kB
dist/lib.es.js  3.38 kB │ gzip: 1.40 kB │ map: 2.11 kB
[vite:dts] Start rollup declaration files...
Analysis will use the bundled TypeScript version 5.4.2
*** The target project appears to use TypeScript 5.5.2 which is newer than the bundled compiler engine; consider upgrading API Extractor.
[vite:dts] Declaration files built in 2947ms.

✓ built in 3.08s
user@wsl:/opt/vite-project$

Reproduction

https://github.com/razorness/vite-dts-compile-errors

Steps to reproduce

  • create new project with template: yarn create vite --template vue-ts
  • add vite-plugin-dts and configure: yarn add --dev vite-plugin-dts
  • add taze to update deps: yarn add --dev taze
  • upgrade all packages by yarn taze major -I
  • append simple export to main.ts
export { default as HelloWorld } from './components/HelloWorld.vue';
  • exec yarn build

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 9 6900HS Creator Edition
    Memory: 9.88 GB / 13.50 GB
    Container: Yes (WSL2)
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.15.0 - ~/.nvm/versions/node/v20.15.0/bin/node
    Yarn: 4.3.1 - ~/.nvm/versions/node/v20.15.0/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.0/bin/npm
  npmPackages:
    @vitejs/plugin-vue: ^5.0.5 => 5.0.5
    vite: ^5.3.1 => 5.3.1
    vite-plugin-dts: ^3.9.1 => 3.9.1

Validations

razorness avatar Jun 24 '24 11:06 razorness