Type definitions are not generated for library mode build
See original GitHub issue⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.
- Read the docs.
- Use Vite >=2.0. (1.x is no longer supported)
- If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.
Describe the bug
Type definitions are not generated for library mode build
Reproduction
- Scaffold a react-ts template project.
- Run build.
- Check the generated assets.
System Info
vite
version: 2.x- Operating System: Mac
- Node version: 14+
- Package manager (npm/yarn/pnpm) and version: npm/yarn
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How do I add types to a Vite library build? - Stack Overflow
I created the project with the vue-ts preset and in my component I have defined props with their types, and used some interfaces....
Read more >TypeScript: Adding Custom Type Definitions for Existing ...
Whether or not a library has type definitions is a big factor in deciding whether I'll use it. You can find the type...
Read more >Build a typescript component library with Vite - Ivancic Josip
To solve the typescript declarations error, we need to generate type declaration files for the components. We will do this using the vue-tsc ......
Read more >How To Bundle TypeScript Type Definitions - Chris Krycho
Create a custom build that puts the type definitions in the root of your package, instead of putting them alongside the compiled JavaScript ......
Read more >Documentation - Module Resolution - TypeScript
Finally, if the compiler could not resolve the module, it will log an error. In this case, the error would be something like...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This works perfectly fine in Vite. @yyx990803 mentioned
--emitDeclarationOnly
flag, but as far as I know, you could get some more advanced options using the@rollup/plugin-typescript
plugin which is very well documented.In package.json
Then
yarn build
This gives me a dist folder containing:
Currently I use
rollup.js
to generate d.ts aftervite
build.rollup.config.js
finished then remove the output file
path.resolve(__dirname,`dist/${name}.dts.js`)
.I make a script
build.js
package.json