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

No types output or weird refs

Open pimjansen opened this issue 10 months ago • 3 comments
trafficstars

Hey, Let me state first, great work on this plugin. Im making a new UI kit and doing a build from my storybook application. The problem is that i keep having an empty types file or that it holds strange internal refs:

import { default as Avatar } from '../../../../../src/components/Avatar';
import { IGebruiker } from '../../../../../src/components/Navbar/Navbar';
import { IMenuItem } from '../../../../../src/components/Navbar/Navbar';
import { IMenuItem as ISidebarMenuItem } from '../../../../../src/components/Sidebar/Sidebar';
import { default as Navbar } from '../../../../../src/components/Navbar/Navbar';
import { default as Sidebar } from '../../../../../src/components/Sidebar/Sidebar';

export { Avatar }

export { IGebruiker }

export { IMenuItem }

export { ISidebarMenuItem }

export { Navbar }

export { Sidebar }

export { }

This is my main build command: tsc -b && vite build

And my vite config file:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import dts from "vite-plugin-dts";
import tsconfigPaths from 'vite-tsconfig-paths';

// https://vite.dev/config/
export default defineConfig({
  build: {
    rollupOptions: {
      external: ['react', 'react-dom', 'react-router', 'tailwindcss'], // Mark peer dependencies as external,
    },
    lib: {
      entry: resolve(__dirname, "src/main.ts"),
      name: 'prisma',
      fileName: 'prisma',
      formats: ["es"],
    },
  },
  resolve: {
    alias: {
      "~": "/src",
    },
  },
  plugins: [
    react(),
    tsconfigPaths(),
    dts({
      tsconfigPath: resolve(__dirname, "tsconfig.app.json"),
      rollupTypes: true,
      exclude: ['src/stories/**/*'],
    }),
  ],
});

My tsconfig.app.json looks like:

{
  "compilerOptions": {
    "baseUrl": ".",
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,
    "paths": {
      "~/*": ["./src/*"]
    },

    /* Bundler mode */
    "moduleResolution": "Bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist", "build"]
}

The weird thing is when running it like this im getting an empty file for my types. My folder structure should be fine i assume:

src
├── components
│   ├── Avatar.tsx
│   ├── Empty.tsx
│   ├── Icon
│   │   ├── ChevronDown.tsx
│   │   ├── ChevronRight.tsx
│   │   ├── Cog.tsx
│   │   ├── Ellipse.tsx
│   │   ├── ExternalLink.tsx
│   │   ├── Help.tsx
│   │   ├── Logout.tsx
│   │   ├── Search.tsx
│   │   ├── types.ts
│   │   └── User.tsx
│   ├── Navbar
│   │   ├── AppsMenuItem.tsx
│   │   ├── AppsMenu.tsx
│   │   ├── Navbar.tsx
│   │   ├── UserMenuItem.tsx
│   │   └── UserMenu.tsx
│   ├── PrismaProvider.tsx
│   └── Sidebar
│       ├── MenuItem.tsx
│       └── Sidebar.tsx
├── main.ts
├── stories
│   ├── Avatar.stories.tsx
│   ├── Button.stories.tsx
│   ├── ExampleIcon.tsx
│   ├── Layout.stories.tsx
│   ├── Link.stories.tsx
│   ├── Navbar.stories.tsx
│   ├── Sidebar.stories.tsx
│   └── translation.ts
├── tailwind.css
├── utils
│   └── twMerge.ts
└── vite-env.d.ts

Hope that someone can assist here

pimjansen avatar Jan 20 '25 09:01 pimjansen

Could this maybe be the same issue as #404? Maybe downgrading to @microsoft/api-extractor 7.48.1 as explained here would solve the problem?

cdauth avatar Mar 01 '25 15:03 cdauth

me too

Image

The build output is not usable like this.

LiMao00 avatar Mar 26 '25 01:03 LiMao00

Same issue, generated file:

// dist/src/index.d.ts
export { default as IndexComponent } from '../../../../../../../../../../src/IndexComponent.vue';

Source file:

// src/index.ts 
export { default as IndexComponent } from "@/IndexComponent.vue";

Relevant tsconfig part:

{
  "paths": { "@/*": ["./src/*"] },
}

Issue disappears if I stop using aliases in the import and replace "@/IndexComponent.vue" with "./IndexComponent.vue".

rijenkii avatar Apr 27 '25 05:04 rijenkii

I'm still encountering this on the latest version 4.5.4 / 1.0.0-beta.0. I am also using path aliases. I can't downgrade to 3.x because I encounter the following error: [vite:dts] Internal Error: Unable to determine module for: *****/src/main.d.ts

@qmhc Any plans on looking at this? It's been nearly 6 months. Thanks.

~Edit: Looks like there might be a PR for this https://github.com/qmhc/unplugin-dts/pull/413/files~

Edit 2: @alexthornton1 is this issue fixed with https://github.com/qmhc/unplugin-dts/commit/3ca6044e537ace29378be8775f083f5858e5e300? Can we get that released? Thanks

jordanranson avatar Oct 01 '25 18:10 jordanranson

Could this maybe be the same issue as #404? Maybe downgrading to @microsoft/api-extractor 7.48.1 as explained here would solve the problem?

This did not fix the issue for me.

jordanranson avatar Oct 01 '25 18:10 jordanranson

@jordanranson 3ca6044 addresses #418, which has only to do with namespace imports (i.e., those of the form import * from Xyz in 'xyz'), so I wouldn't expect it to fix the issue described here.

Just in case you're asking me about when that will be released, I can't help you there. I don't have (and am not looking for) the rights to do that.

alexthornton1 avatar Oct 04 '25 20:10 alexthornton1

All good, thank you.

On Sat, Oct 4, 2025 at 2:06 PM Alex Thornton @.***> wrote:

alexthornton1 left a comment (qmhc/unplugin-dts#405) https://github.com/qmhc/unplugin-dts/issues/405#issuecomment-3368509961

@jordanranson https://github.com/jordanranson 3ca6044 https://github.com/qmhc/unplugin-dts/commit/3ca6044e537ace29378be8775f083f5858e5e300 addresses #418 https://github.com/qmhc/unplugin-dts/issues/418, which has only to do with namespace imports (i.e., those of the form import * from Xyz in 'xyz'), so I wouldn't expect it to fix the issue described here.

Just in case you're asking me about when that will be released, I can't help you there. I don't have (and am not looking for) the rights to do that.

— Reply to this email directly, view it on GitHub https://github.com/qmhc/unplugin-dts/issues/405#issuecomment-3368509961, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFX6Z76JS2R4QS2SND64D33WASD5AVCNFSM6AAAAABVP5HADCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGNRYGUYDSOJWGE . You are receiving this because you were mentioned.Message ID: @.***>

jordanranson avatar Oct 05 '25 22:10 jordanranson