-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
[How To] Use with yarn2 #60
Comments
I investigated this a bit today and ended up fighting for awhile with odd issues. It seems that yarn2 patching is a little temperamental right now, so if you have any problems, let me know. This should work. These instructions are for yarn v3.
|
Thanks @nonara. I was also able to accomplish this by using |
For others: I am using Yarn 2 in Yarn 1 compat mode (meaning node_modules node linker). I had to use |
@jasonkuhrt Could you explain more about the |
@nonara @elby22 I was super excited to read this, I've been really wanting to use the custom transformer typescript-is with my yarn3 create-react-app project. I followed your steps exactly, using the exact same versions of ts-patch and typescript under dependancies, and it all appeared to work. The only indication that something might not be right was the following message on yarn install following the patch-commit, where it stated
The test with I tried unplugging the typescript module before patching, but this had no effect. I tried the latest version of ts-patch and typescript and that failed too, in exactly the same way. I did notice that when running Anyway, if you have any advice on how to fix this, I would love to hear it. Getting those sweet sweet run-time type-checks up and running would be an absolute dream. |
@finnmerlett if you can put together a quick reproduction repo, I'll have a look and see if I can help you get it going! |
@nonara Thank you so much for such a speedy reply, and sorry I took a while to get back to you - I've been quite busy with work. Anyway, I've set it up here https://github.com/finnmerlett/ts-patch-cra-test. Running You can check through the commits on the repo to see how I set it up, but essentially I've just done a create-react-app using their latest alpha build, then set up Yarn 3 with P'n'P. Many thanks in advance! |
@nonara Did you find any leads with this? |
@finnmerlett Sorry. Was swamped and this fell through the cracks. I'll take a look tomorrow and let you know! |
@finnmerlett Ok. I cloned it and had a look. No errors applying hunk for me, but I do see the issue of it not resolving modules. From what I understand, yarn 2 actually modifies common libraries in order to add support. If I recall correctly, it does do this for typescript automatically, as well. As an aside, this seemed, to me, like a terrible route to attempt to solve the issue. I think a better route would be to use a loader to hook filesystem bindings (like we do with Anyway, that's more info than you need. My best guess on this is that some sort of compatibility modification made somewhere is broken. Maybe React is doing a CRC check on TS to add yarn support and it fails because it's modified (??) Hard to say. It's odd that this works outside of React. In my opinion, yarn2's core ideas are excellent and necessary advancements for the node ecosystem. That said, not to be unkind to the developers, but their approach to implementing the ideas have been poorly thought out. In any event, I'm sorry that it didn't work for you. I would recommend trying what other users have reported working for them using node_modules linker / unplugged dependency. Best of luck to you! |
Since it might interest some readers here... After suffering through the ecosystem implications by yarn PnP, I switched to the new |
Thanks @nonara for looking into it (and no worries about the delay - I'm getting your time for free so I'm not complaining!). And ooo @AlCalzone that sounds super interesting. Will investigate further |
Oh boy did I come close. Maybe. I switched to using the Until I tried them out and they weren't working. Their errors suggested that the transformer plugins weren't being applied at all. I can't think what I could be missing, but it feels like something obvious. I have updated the test repo to include the latest changes I made, and the test scripts in App.tsx (they console log their success or errors). The last commit to the repo is the (at first glance apparently successful) applying of ts-patch, so if you want to re-do that yourself just pull the repo and undo the last commit. @nonara is this something you might have time to consider looking further into? It feels like it should work now, we have modules in node_modules as standard, no extra patches applied to typescript and the ts-patch test coming back positive. I'm at a dead end as to what I could be missing! Thanks again for your help. PS. I am still using typescript 4.4.2 and ts-patch 1.x.x in the test repo since those were what you specified in the original instructions, but I want to note that I've also tried it with ts 4.4.4 and ts-patch 2, with the same unsuccessful outcome. PPS. I just had a thought that perhaps react-scripts is somehow finding and using a non-patched typescript package. I don't know where or how though, since running PPPS. I console logged the ts path that react-scripts is using and it matches the ts path that ts-patch confirms it has successfully applied to. This makes me think it might be an issue with ts-patch not applying correctly? |
I would debug and step through, but if your source files are in zips, it's going to be more difficult. Still doable, though. You can insert First thing I'd do is create a local empty plugin and inspect the arguments that it passes. Use tsp v2. If it passes a ts instance, check that Example plugin: export default function () {
console.log(arguments);
debugger;
} Add the local file to your From what you've explained, I can think of a few possibilities
Let me know what you discover and I'll try to offer what ideas I can. |
Hum. So it turns out create-react-app (CRA, the framework I'm using) does what is closest to item no.2 on your list. As I found out (painfully slowly) after stumbling about in the Rightio, this all means ts-patch is out for me. The plugins were applied, but only for typechecking - @nonara thanks for your pointers in helping me figure this out. If I want to get the typescript plugins I was eyeing up working, I need to swap out |
Ah. Good work tracking it down! Thanks for sharing the final details. I imagine that will be helpful for anyone facing the same issue. Good luck with it! |
I was able to make this work with pnpm linker & postinstall script (yarn 3.2.0), thanks above for that. I think a custom yarn plugin would work to apply this patch while still being compatible with yarn's TS patch. |
When installing ts-patch with Yarn 2 (pnp) I get errors regarding undeclared dependencies for
glob
andresolve
:Error: ts-patch tried to access glob, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.
When I resolve these dependencies using my .yarnrc.yaml file in this way:
I get the following error:
[!] [BackupError]: Error backing up tsc.js - Couldn't create backup directory. EROFS: read-only filesystem, mkdir '/node_modules/typescript/lib-backup'
Is there a way to support Yarn 2 with ts-patch?
The text was updated successfully, but these errors were encountered: