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

importing types with "vite-plugin-svgr/client" does not work for "moduleResolution": "node16" #65

Closed
gunters63 opened this issue Dec 12, 2022 · 2 comments

Comments

@gunters63
Copy link
Contributor

gunters63 commented Dec 12, 2022

Typescript requires package exports with condition "types" for subpath imports like "vite-plugin-svgr/client" when moduleResolution node16 is enabled.

Reproduction is easy:

Create a minimal React Typescript App with Vite and add like:

npm create vite@latest node16-bug -- --template react-ts
cd node16-bug
npm install vite-plugin-svgr

Add "types": ["vite-plugin-svgr/client"] to compilerOptions in tsconfig.node.json

Change to "moduleResolution": "node16" in tsconfig.json.

Change all existing relative imports to include the extension to make them compatible to node16 resolution.

Add the svgr plugin to vite.config.ts.

Add a SVG import.

Run type check with tsc --noemit. There will be an error:

error TS2688: Cannot find type definition file for 'vite-plugin-svgr/client'.
  The file is in the program because:
    Entry point of type library 'vite-plugin-svgr/client' specified in compilerOptions

  tsconfig.json:9:30
    9     "types": ["vite/client", "vite-plugin-svgr/client"]
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~
    File is entry point of type library specified here.

For an easy fix add the following to the exports in vite-plugin-svgr package.json:

    "./client": {
      "types": "./client.d.ts"
    }
@pd4d10
Copy link
Owner

pd4d10 commented Dec 12, 2022

Thanks for the feedback! Would you like to send a PR?

@gunters63
Copy link
Contributor Author

ok, done :)

@pd4d10 pd4d10 closed this as completed in 115bc87 Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants