lukeed/clsxPublic

A tiny (239B) utility for constructing `className` strings conditionally.

TS issue importing from clsx/lite

SA

Excited to try out the new `lite` approach:

```ts import { clsx } from 'clsx/lite'; ```

But I'm running into a TypeScript import error:

![CleanShot 2023-12-30 at 13 50 57@2x](https://github.com/lukeed/clsx/assets/169298/1ca7bfbd-c072-4286-b9c5-74eef348c53b)

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

  1. LU

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

  2. SA
    Author

    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!

  3. LU

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

  4. EV

    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.

  5. SA
    Author

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

  6. EvHausmentioned2 years ago on GitHub

  7. EvHaussubscribed2 years ago on GitHub

  8. LU

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

  9. lukeedclosed2 years ago on GitHub

  10. VI

    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"

  11. LU

    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`

  12. VinitSarvadementioned2 years ago on GitHub

  13. VinitSarvadesubscribed2 years ago on GitHub

  14. VI

    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.

  15. lukeedmentioned2 years ago on GitHub

  16. lukeedsubscribed2 years ago on GitHub

  17. droid51referenced this in Cannot find module 'clsx/lite' or its corresponding type declarations #922 years ago on GitHub

  18. droid51referenced this in Lite Version: Improve Typescript Definition and Support for "moduleResolution": "Node" #942 years ago on GitHub