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

typegen does not work with Yarn PnP #9440

Closed
3 tasks
joekrill opened this issue Jan 7, 2025 · 4 comments
Closed
3 tasks

typegen does not work with Yarn PnP #9440

joekrill opened this issue Jan 7, 2025 · 4 comments

Comments

@joekrill
Copy link
Contributor

joekrill commented Jan 7, 2025

Description

I can't use the typegen command because I'm using Yarn PnP. Yarn PnP does not use the traditional node_modules folder, so when the Chakra CLI tool attempt to generate types, I get the following error:

Error: EROFS: read-only filesystem, open '/node_modules/@chakra-ui/react/dist/types/styled-system/generated/conditions.gen.d.ts'

(actually 4 of these errors for each file that is generated).

The typegen tool really shouldn't be writing to the node_modules folder anyway, or assuming it's writable. Would it be possible to specify a custom output folder for these types? Would that even work with how the library reads these types?

This is causing other type errors in my codebase. In particular if I try to use useSlotRecipe for a custom component it returns a never type because - as far as it is concerned - the slot doesn't even exist.

Link to Reproduction

n/a

Steps to reproduce

No response

Chakra UI Version

3.2.5

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

@segunadebayo
Copy link
Member

Good point. We should consider using DTS module augmentation instead. That should work everywhere.

@segunadebayo
Copy link
Member

After looking into this over the weekend, I don't see an easy way around this and would prefer not to support Yarn PnP instead of overcomplicating the codebase.

We've improved the types for useSlotRecipe and useRecipe to avoid the returned never type.

Sorry for the inconvenience. Please consider setting up nodeLinker for Yarn PnP.
https://yarnpkg.com/configuration/yarnrc#nodeLinker

@segunadebayo segunadebayo closed this as not planned Won't fix, can't repro, duplicate, stale Jan 12, 2025
@joekrill
Copy link
Contributor Author

After looking into this over the weekend, I don't see an easy way around this and would prefer not to support Yarn PnP instead of overcomplicating the codebase.

That's unfortunate. It's not about specifically supporting Yarn PnP. It's about not making assumptions about the specific package manager - and really the development environment - being used in general. Even NPM, pnpm, Bun, and Yarn (even with the node linker) all vary slightly in how they handle node_modules.

I think it's a really weird and unexpected behavior to be modifying files inside node_modules. I can't imagine most people expect this sort of thing to be happening.

@joekrill
Copy link
Contributor Author

@segunadebayo Would you still consider the ability to specify a custom output directory for generated types? That would allow a decent workaround. One could then use Yarn's Package patching feature to have correct type information, with a few extra steps:

  1. yarn patch @chakra-ui/react
  2. yarn chakra --outdir=<the_path_generated_in_step_1>/dist/types/styled-system/generated/ ./theme.ts
  3. yarn patch-commit -s <the_path_generated_in_step_1>
  4. yarn

I'd be happy to put up a PR for it if you'd be open to it.

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