How to setup React Monorepo (Lerna, CRA, Typescript, Craco, Yarn Workspaces)

  Рет қаралды 20,872

Tuomo Kankaanpää

Tuomo Kankaanpää

Күн бұрын

Пікірлер: 81
@rehan5383
@rehan5383 2 жыл бұрын
You made my day dear! Hats off to you.... i almost done from this issue at my job but just reached to ur tutorial and in 5 minute my problem solved.
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Cheers, great to hear!
@BulatKhayrullin
@BulatKhayrullin 2 жыл бұрын
Saved my life bro with babel-loader fix in craco
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Great to hear!
@vibekdutta6539
@vibekdutta6539 2 жыл бұрын
The best monorepo video on the internet, hands down!!! Thanks a lot
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Thank you!🙏
@ioannisdeliakos9885
@ioannisdeliakos9885 3 жыл бұрын
Craco did the trick! You're a life saver!
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Great!
@GiovanniDamico-y2k
@GiovanniDamico-y2k Жыл бұрын
Thanks Mr. Tuomo. Best tutorial on the web for this
@TuomoKankaanpaa
@TuomoKankaanpaa Жыл бұрын
Thank you! I’m glad to hear that!
@tienchuan1992
@tienchuan1992 Жыл бұрын
It really is a great comprehensive explanation in detail. helps me a lot.
@TuomoKankaanpaa
@TuomoKankaanpaa Жыл бұрын
Glad to hear that!
@charlesmaddock2492
@charlesmaddock2492 2 жыл бұрын
Thank you so much, excellent video! Much love from Sweden
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Cheers!
@MrNateSpilman
@MrNateSpilman 3 жыл бұрын
Thank you so much!! I've been chasing the wrong leads all morning
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Glad to hear that I could help!
@NguyenNguyen-sw7hq
@NguyenNguyen-sw7hq 3 жыл бұрын
Exactly what I need right now! Thank you!
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Cheers!
@JoseTrezza
@JoseTrezza 2 жыл бұрын
Thanks man, this video has just saved my life!
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Thanks for the comment, glad to hear! 😊🙌
@sametmutevelli
@sametmutevelli 3 жыл бұрын
Awesome tutorial! How would we deploy this parent Lerna application?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
I would deploy the "child" applications seperately . In this case the common packages would not even have to be deployed if it just hosts all the shared components, but you could deploy the web package as you would any other React application.
@aebmyasz
@aebmyasz 2 жыл бұрын
Thanks for doing this great video man! Easy and great explained!!
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Cheers!
@V0idCraftCode
@V0idCraftCode 3 жыл бұрын
Thanks, it was a really helpful video
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Great to hear!
@alekseygladun9990
@alekseygladun9990 2 жыл бұрын
Great explanation! Thanks a lot!
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Cheers!
@adeoluayangade3772
@adeoluayangade3772 2 жыл бұрын
This is an amazing explanation, I have a question, Let us assume that the common package is not a react app but a normal npm package that exposes a bunch of functions we would like to call in the web package. How would your current configuration change things?
@minhpn2253
@minhpn2253 Жыл бұрын
Great video! Thanks
@TuomoKankaanpaa
@TuomoKankaanpaa Жыл бұрын
Glad you liked it!
@paraxo37
@paraxo37 2 жыл бұрын
It seems using absolute import paths inside common folder between components is not possible with this setup. Any idea how to resolve that?
@MyNameIsYan
@MyNameIsYan 3 жыл бұрын
From 2:45 to 2:50, you have yarn.lock file and node_modules at your root project folder, how did you get that? Tried doing the same steps before 2:45 but I don't see that in my directory
@MyNameIsYan
@MyNameIsYan 3 жыл бұрын
Also what yarn version are you using? Thank you!
@AlexanderSavchenko91
@AlexanderSavchenko91 3 жыл бұрын
thank you! that is what I was looking for !)
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Great!
@julianklumpers
@julianklumpers 2 жыл бұрын
Hi, nice video. How about importing assets? let's say Button imports a svg, and you use that button in another package. It gives me an error it cannot resolve .svg
@oscar_cornejo
@oscar_cornejo 3 жыл бұрын
How to add the storybook?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
I installed it normally to one of the packages and it worked well.
@oscar_cornejo
@oscar_cornejo 3 жыл бұрын
@@TuomoKankaanpaa great thanks ... i will try! ✌
@huyho4370
@huyho4370 2 жыл бұрын
Thanks for your great share, my application is using nextjs can you guide how to configure webpack?
@huyho4370
@huyho4370 2 жыл бұрын
Step Craco configuration explained
@cc-hc1dr
@cc-hc1dr 3 жыл бұрын
What about production builds? Is the /common lib pulled into the production build of the /app then or do you need to publish /common? How would you handle if you had 2 different apps using different versions of common lib?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
The files used by app from common are included in the production build of the app. One way to handle using 2 different versions of common is to publish it to npm for example and that way you can reference them like you would any npm package.
@cc-hc1dr
@cc-hc1dr 3 жыл бұрын
@@TuomoKankaanpaa Thanks, I do use a private NPM repo, I'm just trying to understand how that development workflow would work. You'd need to update version, and build every time you change common, and then install latest common for the app? So I think you wouldn't have any of the advantage of seeing changes right away with the CRACO transpile?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
@@cc-hc1dr Yea I would say that if you use npm and you have different versions there, then you need to build common when you make changes and publish it and then update your app too, so you wouldn't get the advantage of the Craco transpile. If you use the code from the common directly and not through npm, then all you should need to do is to build your app and you are good to go. If there is someone here who knows better, feel free to correct me if I'm mistaken :)
@Kevin-fl8rh
@Kevin-fl8rh 3 жыл бұрын
고맙습니다 형님, 구독했습니다.
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Thanks!
@israelsantiago7256
@israelsantiago7256 2 жыл бұрын
Awesome! it is just exactly what I need, just a quick question... in the web/App.tsx when importing the Button, the package name shows an error that says: "Cannot find module '@tuomo/common' or its corresponding type declarations." any idea?
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Is it showing that error in VS Code and is the app still working or is that error blocking the app from working?
@jayashriborse8783
@jayashriborse8783 2 жыл бұрын
Thank you very much!
@TuomoKankaanpaa
@TuomoKankaanpaa 2 жыл бұрын
Cheers!
@riccardogrossano7099
@riccardogrossano7099 3 жыл бұрын
Hi Tuomo. I'm continuing to study Yarn. I saw in your video that you're using the classic version of Yarn (or 1.x) and not Berry version (now 3.x). Is there a particular reason?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Hi and thanks for the question! There is no particular reason, I just haven't updated it and now that you mentioned that it is already in version 3.x I am actually going to look into updating it!
@riccardogrossano7099
@riccardogrossano7099 3 жыл бұрын
Thank you! I have a question. I tried to install material-ui in the "common" package to use as a base for my graphics components. But when I import the component on the web it gives me an error. Do you have the solution for this problem?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
It's hard to say without knowing more about the error. If you are using the material ui components in your custom components inside common and then importing your custom components in the web package, there shouldn't be any problem with that. But if you are directly importing the material ui components then you should just install material ui to your web package.
@riccardogrossano7099
@riccardogrossano7099 3 жыл бұрын
@@TuomoKankaanpaa Thanks for the reply. The error: " Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app [...] ". I created a button from the material-ui button. If I create it from the html "button" tag everything works fine. I also tried to use other external libraries and they all give me the same error. Is it possible that the problem is npm (I didn't use yarn)?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
@@riccardogrossano7099 The reason could very well be that you didn't use yarn, so I would recommend using it instead of npm. If that doesn't help, here is a good article on solving that error you got: reactjs.org/warnings/invalid-hook-call-warning.html If anything from there doesn't help, this issue has more discussion about the problem: github.com/facebook/react/issues/13991
@riccardogrossano7099
@riccardogrossano7099 3 жыл бұрын
​@@TuomoKankaanpaa I had already found it but it didn't solve the problem - I'll be using yarn ;)
@riccardogrossano7099
@riccardogrossano7099 3 жыл бұрын
Ok i tried with yarn and works fine. The problem is npm 👍
@TheOnlyGodInTheWorld
@TheOnlyGodInTheWorld 3 жыл бұрын
node_modules on every package?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Yea there is node_modules on every package but if there is common dependencies between packages, they are placed inside the root node_modules so there is no duplication.
@TheOnlyGodInTheWorld
@TheOnlyGodInTheWorld 3 жыл бұрын
@@TuomoKankaanpaa make sense! thanks
@georgesava1
@georgesava1 3 жыл бұрын
Does auto import work in this setup?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
I'm not sure, would have to test that out. Let me know if you find out before I do!
@petarkolev6928
@petarkolev6928 3 жыл бұрын
Do you guys have issues using PRIMEREACT in the monorepo? PRIMEREACT class names aren't applying. Sometimes they work for an hour and after that they stop for good which is super super strange.
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
I don’t have experience about that unfortunately
@sabobin
@sabobin 3 жыл бұрын
Thanks for this, this is literally the exact problem I've been struggling with for two days. I wonder though if there is some way to achieve it without craco?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Great to hear that the video helped! I don't know about that, I found using Craco the best way when I was implementing this myself, but if you find another way be sure to let me know too! :)
@sabobin
@sabobin 3 жыл бұрын
Yeah this is great I'm just curious if there is some way to do it without adding another dependency. I noticed turborepo seems to be able to handle this scenario without craco (no idea how). Thanks again.
@rogerprz
@rogerprz 3 жыл бұрын
Could you do a video using webpack instead of craco?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Can you elaborate a little please? :)
@jonasboardwalker
@jonasboardwalker 3 жыл бұрын
Hi man, I think this is a very helpful tutorial, but I have a problem: when I export compoenent from the package, VS code complains that it can not find the module. Is there a way to fix this?
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
Thanks! Make sure you have named your packages in the package.json file properly and you run lerna bootstrap in the root level. Hope this helps!
@akashvhotkar8617
@akashvhotkar8617 Жыл бұрын
Thanks You
@TuomoKankaanpaa
@TuomoKankaanpaa Жыл бұрын
Cheers!
@rouabahoussama
@rouabahoussama 3 жыл бұрын
Is this monorepo ? I think you should have only one node_modules but in your case, you have multiple node_modules ( one in web, and the other in common ) . I don't think this is a good setup. Anyway thanks for the video, but I think there is a better way using Nx ( which is a real monorepo ).
@TuomoKankaanpaa
@TuomoKankaanpaa 3 жыл бұрын
I’d say this is monorepo too. All the shared dependencies will be in the root level node_modules and if e.g. web uses different version of a dependency than common, then the specific versions will be placed inside each package’s node_modules
I Never Want to Create React Forms Any Other Way
9:50
Tuomo Kankaanpää
Рет қаралды 899
Why I’m using a monorepo with Yarn workspaces
9:18
Web Dev Cody
Рет қаралды 29 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
Yarn Workspaces Tutorial
11:01
Ben Awad
Рет қаралды 62 М.
No BS TS #32 - Monorepos with NX
9:19
Jack Herrington
Рет қаралды 17 М.
Lerna Crash Course
10:47
Nx - Smart Monorepos - Fast CI
Рет қаралды 15 М.
Yarn Workspaces Setup - Multiple JavaScript Packages (Mono-Repo)
14:27
Why use a monorepo?
6:32
Vercel
Рет қаралды 110 М.
How to setup a Yarn workspace with Typescript
10:03
Ben Awad
Рет қаралды 24 М.
Creating a Rush Monorepo with a React App and Shared Component Library
24:54
Monorepos: Yarn Workspaces and Lerna for beginners!
24:19
Mostly Code
Рет қаралды 10 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19