Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bogus typescript errors related to default imports during since 4.x #363

Closed
3 tasks done
silverwind opened this issue Aug 7, 2024 · 5 comments
Closed
3 tasks done
Labels
pending Need further confirmation

Comments

@silverwind
Copy link

silverwind commented Aug 7, 2024

Describe the bug

Since 4.x, I observe that this plugin prints typescript errors during npx vite build, related to default imports. npx tsc does not show these errors, so I think they are bogus and a bug in this plugin.

Reproduction

https://github.com/silverwind/dts-4-react-issue

Steps to reproduce

Clone and run npm i && npx vite build, observe these bogus errors:

index.tsx:2:33 - error TS2604: JSX element type 'Select' does not have any construct or call signatures.

2 export const Component = () => <Select/>;
                                  ~~~~~~
index.tsx:2:33 - error TS2786: 'Select' cannot be used as a JSX component.
  Its type 'typeof import("node_modules/react-select/dist/react-select.cjs")' is not a valid JSX element type.

2 export const Component = () => <Select/>;

System Info

System:
    OS: macOS 14.5
    CPU: (16) arm64 Apple M3 Max
    Memory: 2.10 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.5.1 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /opt/homebrew/bin/npm
    pnpm: 9.6.0 - ~/.npm-global/bin/pnpm
    bun: 1.1.21 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 127.0.6533.89
    Firefox Nightly: 129.0a1
    Safari: 17.5
  npmPackages:
    vite: 5.4.0 => 5.4.0
    vite-plugin-dts: 4.0.1 => 4.0.1

Validations

@qmhc qmhc added the pending Need further confirmation label Aug 9, 2024
@silverwind
Copy link
Author

silverwind commented Aug 20, 2024

Another way to reproduce is to perform this import in a vite.config.ts:

import type {UserConfig} from "vite";

It shows error TS2305: Module '"vite"' has no exported member 'UserConfig' which is bogus and works just fine in tsc.

@dumptyd
Copy link

dumptyd commented Aug 26, 2024

I was getting similar errors. In my case, explicitly specifying tsConfigPath did the trick.

image

@silverwind
Copy link
Author

No change for me when I try this in the reproduction repo:

tsconfigPath: fileURLToPath(new URL("tsconfig.json", import.meta.url)),

@qmhc qmhc closed this as completed in a04a191 Aug 28, 2024
@qmhc
Copy link
Owner

qmhc commented Aug 28, 2024

You should also add @types/react as a dev dependency.

@silverwind
Copy link
Author

Yeah indeed. I forgot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending Need further confirmation
Projects
None yet
Development

No branches or pull requests

3 participants