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

TS issue importing from clsx/lite #89

Closed
sambecker opened this issue Dec 30, 2023 · 9 comments
Closed

TS issue importing from clsx/lite #89

sambecker opened this issue Dec 30, 2023 · 9 comments

Comments

@sambecker
Copy link

Excited to try out the new lite approach:

import { clsx } from 'clsx/lite';

But I'm running into a TypeScript import error:

CleanShot 2023-12-30 at 13 50 57@2x

Is there something I'm doing wrong? Installed clsx 2.1.0 via pnpm 8.12.1

@lukeed
Copy link
Owner

lukeed commented Dec 30, 2023

Hmm… clear cache maybe? Perhaps where you’re writing this is resolving to an older version? Eg clsx@2.0 within a workspace

@sambecker
Copy link
Author

sambecker commented Dec 30, 2023

It was on a project which did not have a prior version of clsx. Tried removing the lock file and deleting node_modules. Will try clearing the cache next!

@lukeed
Copy link
Owner

lukeed commented Dec 30, 2023

Oh. Play with your tsconfig settings for module/moduleResolution. Only certain combos respect the exports map

@EvHaus
Copy link

EvHaus commented Jan 1, 2024

Changing "moduleResolution": "node" to "moduleResolution": "bundler" in tsconfig.json worked for me but that caused some other TS issues I had to resolve in my project.

@sambecker
Copy link
Author

sambecker commented Jan 3, 2024

Switching to "moduleResolution": "Bundler" worked for me—thx for the tip @EvHaus!

@lukeed
Copy link
Owner

lukeed commented Jan 5, 2024

Closing as this is a TypeScript (tsconfig) setting, answered above.

@lukeed lukeed closed this as completed Jan 5, 2024
@VinitSarvade
Copy link

Changing the moduleResolution is not an option when using nextjs.

The following mandatory changes were made to your tsconfig.json:
        - moduleResolution was set to node (to match webpack resolution)

The value get's set back to node when changed to "Bundler"

@lukeed
Copy link
Owner

lukeed commented Feb 9, 2024

Gotta love it... In such case @VinitSarvade, you can/should just use clsx since the size difference is effectively nothing. The __intertop helpers your Next config will inject into your output are larger than clsx itself, let alone the difference between clsx/lite and clsx.

If you really want to use clsx/lite here, you can set up a "path alias" or "resolve alias" within Next.js config which will map clsx to clsx/lite at build time. However, since you'd still be using clsx imports, typescript will use/follow the dts for clsx

@VinitSarvade
Copy link

Thank you for the explanation @lukeed. I like the idea of path alias, but like you mentioned the difference is not really much. The larger goal was mostly to ensure a uniform string arguments only option.

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

4 participants