Lib mode doesn't export types
See original GitHub issueDescribe the bug
I’m using vitejs to build a react typescript library, I started building it with a plain rollup, but decided to migrate, so I have put everything accordingly. Fixed some bugs, added some packages, but when I export it, it doesn’t export the typings (.d.ts) along with the es and umd files, even if I set declarations to true inside of the tsconfig. But it does export successfully both files.
I tried tweaking rollup but to no avail, and also couldn’t find anything related to this in the issues or google at all.
Reproduction
Install vite with the “react-ts” template, follow the documentation steps to use lib mode, make a simple component and export it from the output file, and build it.
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
System:
OS: Windows 10 10.0.18363
CPU: (8) x64 Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
Memory: 10.24 GB / 15.96 GB
Binaries:
Node: 14.3.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.14.0 - D:\programas\laragon\bin\yarn\bin\yarn.CMD
npm: 5.7.1 - ~\node_modules\.bin\npm.CMD
Browsers:
Chrome: 89.0.4389.128
Edge: Spartan (44.18362.1474.0)
Internet Explorer: 11.0.18362.1
Used package manager: yarn
Before submitting the issue, please make sure you do the following
- [ x ] Read the Contributing Guidelines.
- [ x ] Read the docs.
- [ x ] Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- [ x ] Provide a description in this issue that describes the bug.
- [ x ] Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- [ x ] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Comments:26 (9 by maintainers)
Top GitHub Comments
I understand the reasoning behind not doing this but I think it should be reconsidered. If Vite did this by default it would be a sort of pit of success that would benefit the broader JS/TS community. If it’s not the default and people start using Vite to build libraries I imagine we will have lots of them published without types. That in turn will lead to a lot of churn and lots of github issues being created (in the respective libraries).
You can use https://github.com/egoist/tsup.
Example usage,
The
--dts
flag generates the types automatically.