question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lib mode doesn't export types

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:26 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
moljac024commented, May 3, 2021

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).

3reactions
axelthatcommented, Apr 24, 2021

You can use https://github.com/egoist/tsup.

Example usage,

{
    "scripts": {
        "build": "tsup index.ts --format esm,cjs,iife --dts --minify"
    }
}

The --dts flag generates the types automatically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Export and publish all types and interfaces in Typescript
I am generating declaration files by setting tsconfig.json param "declaration":"true" . Now I want to use this libraries as dependency of ...
Read more >
How to export artwork in Illustrator - Adobe Support
Learn how to export your artwork from Illustrator and the various export options of the supported file formats. It's always good to export...
Read more >
Export photos, videos, slideshows, and memories in Photos ...
In the Photos app on your Mac, select the item you want to export. Choose File > Export > Export [number] Photos. Click...
Read more >
isolatedModules - TSConfig Option - TypeScript
Exports of Non-Value Identifiers. In TypeScript, you can import a type and then subsequently export it: ts. import { ...
Read more >
Build Options - Vite
Note: the polyfill does not apply to Library Mode. ... This is the same as options that can be exported from a Rollup...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found