unplugin-dts icon indicating copy to clipboard operation
unplugin-dts copied to clipboard

源文件的.d.ts中的内容无法在构建后的文件中看到

Open tangerball opened this issue 1 year ago • 2 comments

Describe the bug

1、模块解析错误: 当我在 vite.config.js 中设置 rollupTypes: true 时,Vite 报错 [vite:dts] Internal Error: getResolvedModule() could not resolve module name "../types/axios.d"。 2、类型声明文件未包含在构建输出中: 当我同时设置 rollupTypes: true 和 copyDtsFiles: true 时,我发现 types/axios.d.ts 文件的内容并没有出现在构建输出目录 dist 中的 index.d.ts 文件里。 3、目录规划问题: 如果只设置 copyDtsFiles: true,虽然可以将类型声明文件复制到构建输出目录,但这并不符合我后期库的多入口文件目录规划。

Reproduction

/

Steps to reproduce

types/axios.d.ts

import 'axios'

declare module 'axios' {
    isNeedToken?: boolean
}

export * from 'axios'

src/index.ts

const test=()=>{}

export * from '../types/axios.d'

export default test

vite.config.js

import { defineConfig } from 'vite'
import { resolve } from 'path'
import dts from 'vite-plugin-dts'

export default defineConfig({
  plugins: [
    dts({
      tsconfigPath: resolve(__dirname, 'tsconfig.json'),
      rollupTypes: true,
      copyDtsFiles: true,
    }),
  ],
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'MyLibrary',
      formats: ['es', 'cjs', 'umd', 'iife'],
      exports: 'named',
      fileName: (format) => `index.${format}.js`,
    },
  },
})

System Info

vite 5.1.18
vite-plugin-dts 3.7.3
typescript 5.6.2

Validations

tangerball avatar Dec 11 '24 03:12 tangerball

您好,我也遇到类似问题了,请问有解决方案吗

xiyure avatar Apr 07 '25 08:04 xiyure

可以尝试将 axios.d.ts 更改为 axios.ts

qmhc avatar Jul 31 '25 03:07 qmhc