Skip to content

DTS not compatible with latest React Vite tsconfig structure #344

@mochizin

Description

@mochizin

Describe the bug

I'm trying to use DTS with Vite for React 5.3.1
In this version Vite introduced tsconfig.app.json and reference it in tsconfig.json:

{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.node.json"
    }
  ]
}

For some reason, the tsconfig.app.json is not being recognized by DTS. I get the following error:

image
or
Module './App.tsx' was resolved to 'libray-ui/src/App.tsx', but '--jsx' is not set.
image

The solution that I'm using is add tsconfigPath: "./tsconfig.app.json", Is this a good solution? Edit: This solution doesn't work properly

plugins: [
    react(),
    dts({
      tsconfigPath: "./tsconfig.app.json"
    }),
  ],

Reproduction

https://stackblitz.com/edit/vitejs-vite-yxnnz2?file=vite.config.ts

Steps to reproduce

  • Run:
    npm create vite@latest
    npm install @types/node
    npm install --save-dev vite-plugin-dts

  • vite.config.ts

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

export default defineConfig({
  plugins: [
    react(),
    dts(),
  ],
  build: {
    lib: {
      entry: resolve(__dirname, "src/main.ts"),
      name: "trigger-ui",
      formats: ["es"],
      fileName: "trigger-ui",
    },
    rollupOptions: {
      external: ["react", "react/jsx-runtime"],
    },
  },
});
  • main.tsx file
export const Card = ({ children, ...props }: CardTypes) => {
  return <button {...props}>{children}</button>;
};

type CardTypes = {
  children: string;
} & React.ComponentPropsWithoutRef<"button">;
  • Run
    npm run build

System Info

System:
    OS: Windows 11
  Binaries:
    Node: 20.11.1
    npm: 10.2.4
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1
    vite: ^5.3.1 => 5.3.1
    vite-plugin-dts: ^3.9.1 => 3.9.1

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions