qmhc / vite-plugin-dts

A Vite plugin for generating `.d.ts` files.
MIT License
1.32k stars 91 forks source link

[vite:dts] Cannot read properties of undefined (reading 'length') #387

Open webkong opened 1 month ago

webkong commented 1 month ago

Describe the bug

When I use dts according to documentation.

import dts from "vite-plugin-dts";

plugins: [dts()]

image

I'm try to fix the bug. Add a ? can resove.

image

Reproduction

no url

Steps to reproduce

No response

System Info

System:
    OS: macOS 15.0.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 71.48 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
  Browsers:
    Chrome: 129.0.6668.91
    Safari: 18.0.1
  npmPackages:
    vite: ^5.4.8 => 5.4.8 
    vite-plugin-dts: ^4.2.3 => 4.2.3

Validations

qmhc commented 1 month ago

Could you show how did you trigger this error?

webkong commented 1 month ago

just

import dts from "vite-plugin-dts";

plugins: [dts()]

tsconfig

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,

    /* declaration */
    "declaration": true,
    "declarationDir": "./types",

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"]
}
iHeart-JeffSkee commented 4 weeks ago

I've encountered the same exact experience as described by @webkong.

After messing with it and debugging for WAY tooo long, I finally discovered that I was setting

export default defineConfig({
  build: {
    rollupOptions: { plugins: [dts({ rollupTypes: true })] },
    ...
  }
})

When I should have been setting

export default defineConfig({
  plugins: [dts({ rollupTypes: true })],
  build: {
    ...
  },
});

Seems like it's always the little things that trip you up