Setting Up a React Native Web Monorepo

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 90

  • @allaheadflank
    @allaheadflank 5 лет назад +3

    Thanks for picking new tech/concepts for the series!

  • @ericlif1
    @ericlif1 4 года назад +1

    If you are still getting the "Can't resolve 'react-native' in '.../common'" make sure you have the common package set to private in package.json ("private": true) and also make sure you have react-native installed correctly on the web package.
    Thanks for this series of tutorials!

  • @nald-dev
    @nald-dev 3 года назад

    I'm confused with react-native-web documentation, how to set up a react-native-web monorepo for android, iOS and web, finally found this video and it helps me, thanks

  • @gonzalochristobal
    @gonzalochristobal 5 лет назад +3

    In case someone is getting a "Hooks can only be called inside the body of a function component" when running the server, i ran into the same issue when setting my workspace, related issue:
    @t
    And as @gaearon explained it was occasioned because there were two different copies of react, reading through i figure out that my yarn.lock file was messing up the dependencies, because i had two different versions of React, at the time of doing this series, react-cli comes with React 16.8.4, and the series use 16.8.4, because of that i had duplicated dependencies occasioning a unexpected no-hoist in my common package, i fixed the problem copying the yarn.lock file from Ben's repo, deleting node_modules and running yarn, you can also solve it manually as explained in this Medium post:
    @t

    • @gonzalochristobal
      @gonzalochristobal 5 лет назад

      Links
      github.com/facebook/react/issues/14317
      medium.com/@scinos/de-duplicating-yarn-lock-ae30be4aa41a

    • @gonzalochristobal
      @gonzalochristobal 5 лет назад

      ​@@happygaljoo2203 download the yarn.lock file from the repo github.com/benawad/react-native-web-series/tree/1_monorepo_setup and replace it in your folder

    • @happygaljoo2203
      @happygaljoo2203 5 лет назад

      @@gonzalochristobal I tried this, and I am still getting the same error: Hooks can only be called inside the body of a function component. (fb.me/react-invalid-hook-call)

    • @davidhahn7391
      @davidhahn7391 5 лет назад

      @@happygaljoo2203 try deleting your node_module files and reinstall using 'yarn' using @ben's yarn.lock

    • @danielfloyd4559
      @danielfloyd4559 5 лет назад

      I had the same issue and getting this yarn.lock file worked for me.

  • @MohamedSaleh01
    @MohamedSaleh01 5 лет назад +3

    Didn't know we could do `rm -rf packages/*/node_modules` cool!

  • @bawad
    @bawad  5 лет назад +1

    Getting React Native setup with symlinks is tricky right now. The React Native team will be fixing this shortly, so if you run into any trouble I recommend moving on to the next video and not worry about the native portion until they fix it.

    • @lancerino765
      @lancerino765 5 лет назад

      It is okay to not setup the React Native part right ?

    • @bawad
      @bawad  5 лет назад

      Yes

  • @davidseek
    @davidseek 2 года назад

    Thank you for putting this together. Highly appreciated. Learned a lot.

  • @we.are.awakening
    @we.are.awakening 5 лет назад +2

    I get the error message: "Hooks can only be called inside the body of a function component. (fb.me/react-invalid-hook-call)" Why is that? I've checked all the versions of the dependencies and it seems I got it all correct. Thank you, super interesting tutorial! Solved: react-dom and react were on different versions

  • @gablabelle
    @gablabelle 5 лет назад

    Thanks! Would of been great if the common folder was a standalone storybook project in which you could develop and test components in isolation. Was unable to find ressources on how to properly setup "Storybook + Typescript + React Native"

    • @bawad
      @bawad  5 лет назад

      I think I tried that a couple months ago and didn't have much luck with it. Might give it another try sometime though

    • @gablabelle
      @gablabelle 5 лет назад +1

      @@bawad I did some work today. I had a hard time but now have a work in progress here github.com/gablabelle/react-native-web-storybook-typescript

  • @marian_tsx
    @marian_tsx Год назад

    How are you adding @wow/common into the dependencies like this if it's not in a registry? I'm getting the error where is trying to search it within a registry url and ofc, it's not, so packages won't install.

  • @HieuNguyen-xt8ko
    @HieuNguyen-xt8ko 3 года назад

    Why did Ben use "module": "commonjs" in the tsconfig.json file inside the "common" package? Why not use "esnext" or other?

  • @5ervanttechintel_github_io979
    @5ervanttechintel_github_io979 5 лет назад +2

    *Can you help how can I `import App from '@es6-app/common' ?*
    "..\common\package.json" has `"main": "src/App.js"` property.

    • @bawad
      @bawad  5 лет назад

      What error are you getting? Is App undefined?

    • @5ervanttechintel_github_io979
      @5ervanttechintel_github_io979 5 лет назад

      ​@@bawad
      import React, { Component } from 'react';
      ^^^^^
      SyntaxError: Unexpected identifier
      *AND*
      [ error ] ../common/src/App.js 24:6
      Module parse failed: Unexpected token (24:6)
      You may need an appropriate loader to handle this file type.
      | render() {
      | return (
      >

    • @bawad
      @bawad  5 лет назад

      I'm not sure how to fix that for js

    • @5ervanttechintel_github_io979
      @5ervanttechintel_github_io979 5 лет назад

      @@bawad I restored to use the original "App.js" and the error does changed to:
      `````
      ../common/src/App.js 19:5
      Module parse failed: Unexpected token (19:5)
      You may need an appropriate loader to handle this file type.
      | });
      |
      > type Props = {};
      | export default class App extends Component {
      | // export default class App extends Component {
      `````
      Maybe I also need a TypeScript compiler for that.
      If I convert it to ES6, maybe I need to use Babel or Webpack.

    • @bawad
      @bawad  5 лет назад

      You can still use JavaScript with the typescript compiler so I would give that a try

  • @mjabadilla
    @mjabadilla 5 лет назад

    @Ben Awad, thanks for sharing! Would it break if we just add react-native-web on the existing react-native repo? Does the common/dist folder generate optimized code with tree shaking or do we need to add it?

    • @bawad
      @bawad  5 лет назад +1

      I don't think react-native-web breaks the react-native project but react-native breaks the web project

  • @theo-bit
    @theo-bit 5 лет назад

    Hi, can you please add the link to the previous videos, that you created the 'MyOwesomeProject' and the 'react-native-series' one ?

    • @bawad
      @bawad  5 лет назад +1

      ruclips.net/p/PLN3n1USn4xll9wq0rw0ECrO0j2PFzuXtn

  • @codeu2022
    @codeu2022 4 года назад

    yarn install just crate one node_modules in packages, not inside app and web folder

  • @jesusaromeroz
    @jesusaromeroz 5 лет назад

    Awesome course Ben, thanks for doing this. Can this configuration be used on a Javascript project instead of a Typescript?, because right now we are working in a React Native Web project, but it won't use Typescript :(

    • @bawad
      @bawad  5 лет назад

      Yeah you can use JavaScript in a typescript setup

  • @Lessep922
    @Lessep922 5 лет назад

    Awesome Ben! Would like to ask you the following scenario: What if you have to use specific package that just works in mobile (ex: react-native-navigation)? If you're getting the main app entry from @wow/common and reusing in both projects (mobile & web) how do you deal with such problem? I guess you'll have to redeclare main apps? Thanks!

    • @bawad
      @bawad  5 лет назад

      react-native-navigation would be difficult because it would effect most parts of the application. If it only occurs in one component, we can create 2 different versions of that component.

  • @engpedro86
    @engpedro86 5 лет назад

    I have got an error that I described here: stackoverflow.com/questions/57717853/error-registering-package-in-react-native-application-how-do-i-solve-it. Please someone help me with this.

  • @jasonjones5079
    @jasonjones5079 5 лет назад

    How many "node_module" directories should we be having with this setup? I have four so far (one at my-monorepo, and three more in app, common, and web directories). Not sure if these all should be there or if they are supposed to get hoisted up into one main "node_modules" directory at my-monorepo level.

    • @MattHagner
      @MattHagner 5 лет назад +1

      There should be a node_modules folder in the root of the workspace, and in each of the directories in the packages folder. If I understand correctly workspaces does some work to prevent duplicate installs of the same version of the same npm packages across the workspace and uses linking to handle the sub-packages node_modules folders.

    • @jasonjones5079
      @jasonjones5079 5 лет назад +1

      @@MattHagner Thanks!

  • @SaleemKhan-ln3ly
    @SaleemKhan-ln3ly 4 года назад

    I was trying the same thing with javascript, but I got stuck at compiling common code into dist folder. Is there any equivalent way of compiling jsx into dist folder?

    • @SaleemKhan-ln3ly
      @SaleemKhan-ln3ly 4 года назад

      I allowed js in tsconfig and its compiing with tsc.

  • @robbtthhh1642
    @robbtthhh1642 4 года назад

    How is the react-native jsx in common being translated into readable code for the web?

    • @bawad
      @bawad  4 года назад +1

      Webpack replaces all react-native imports with react-native-web

  • @martinnordstrom3213
    @martinnordstrom3213 5 лет назад +4

    that thumbnail tho

  • @tahasoft1
    @tahasoft1 5 лет назад

    Awesome as usual! When I press ctrl + period it doesn't show me import suggestions

    • @bawad
      @bawad  5 лет назад

      and your cursor is at the end of the word like mine?

    • @bawad
      @bawad  5 лет назад

      React Native Text doesn't work for me either. I use Ctrl + Space for that

  • @sankarr5680
    @sankarr5680 5 лет назад

    I got the following error, while trying to execute 'yarn build' command inside '../web/ 'directory
    There might be a problem with the project dependency tree.
    It is likely not a bug in Create React App, but something you need to fix locally.
    The react-scripts package provided by Create React App requires a dependency:
    "jest": "23.6.0"
    Don't try to install it manually: your package manager does it automatically.
    However, a different version of jest was detected higher up in the tree:
    F:\monorepo\test-development
    ode_modules\jest (version: 24.1.0)
    Manually installing incompatible versions is known to cause hard-to-debug issues.
    If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
    That will permanently disable this message but you might encounter other issues.

    • @bawad
      @bawad  5 лет назад

      you should be running build inside of the common package, but you can also add SKIP_PREFLIGHT_CHECK to the build command in the web package

  • @dal3xander15
    @dal3xander15 4 года назад

    can i do this without typescript?

    • @bawad
      @bawad  4 года назад

      yeah, typescript can compile javascript files

  • @sirax1414
    @sirax1414 4 года назад

    It installs all the dependencies for web in the root `node_modules` folder, why it doesn't happen to you? my proyect isn't starting since it does not find all the dependencies inside web folder... HEEEEELP PLS!

    • @bawad
      @bawad  4 года назад

      have you tried cloning my code?

  • @jorgezevallos5064
    @jorgezevallos5064 5 лет назад

    Hello Ben,
    I am quite new on react-native. I try to set the mono-repo only with web but showing me the next error
    ../common/dist/index.js
    Module not found: Can't resolve 'react-native' in '/Users/jorgezevallos/Coding/react/MonoRepo/packages/common/dist'
    I try to copy the exactly package.json from your GitHub but no working.
    Any suggestions?

    • @bawad
      @bawad  5 лет назад

      Getting React Native setup with symlinks is tricky right now. The React Native team will be fixing this shortly, so I recommend moving on to the next video and not worry about the native portion until they fix it.

    • @trieulee4739
      @trieulee4739 5 лет назад

      I have same problem too. I don't understand I create a project by my self and it got this problem.But I clone a git repo from Ben and it don't have this problem

    • @umehchukwuemeka2906
      @umehchukwuemeka2906 5 лет назад

      @Ben Awad, Thanks for the tutorials, for WEB setup, I keep getting the same error as @Jorge Zevallos said as well. I have tried everything but no avail. It says Module not found in the index file in the dist directory But when I check it, the React-Native package is there(it references the root directory node_modules) but when I run "yarn start", the same problem appears. Pls, can you tell me what to do?

    • @bawad
      @bawad  5 лет назад

      have you tried comparing your code against mine?

    • @umehchukwuemeka2906
      @umehchukwuemeka2906 5 лет назад

      @@bawad Yea, I have compared the package.json in both web and common. the only difference is that I am using React 16.8.3 and React-Native 0.59.1.

  • @unlimitself
    @unlimitself 5 лет назад

    Why not have one package for both app and web and use Platform "if" conditions for rare device specific logics?

    • @bawad
      @bawad  5 лет назад

      it's a little cleaner to split up the react-native and create-react-app boilerplate

    • @jsp3536
      @jsp3536 5 лет назад

      I am wondering this also. You could use file.ios.js , file.android.js, and file.web.js extensions when you need the entire components to be different

  • @三三道海子
    @三三道海子 5 лет назад

    Will this course continue to be updated?

    • @junka3
      @junka3 5 лет назад

      Hopefully using play js. hes workspace seems fun

    • @bawad
      @bawad  5 лет назад

      Come learn typescript :)

    • @bawad
      @bawad  5 лет назад

      Yeah I'll do an updated monorepo for react native when symlinks work

    • @三三道海子
      @三三道海子 5 лет назад

      @@bawad
      Master: how do you enter the typescript course, is there a course link? Thanks :)

    • @三三道海子
      @三三道海子 5 лет назад

      @@bawad Yeah,very nice!

  • @mahmoudalmontasser8369
    @mahmoudalmontasser8369 5 лет назад

    Did you checkout Flutter? It looks promising ✨

    • @bawad
      @bawad  5 лет назад +1

      I haven't yet, but I do want to try it

  • @cunningham.s_law
    @cunningham.s_law 5 лет назад

    thoughts on lerna?

    • @bawad
      @bawad  5 лет назад +1

      I like it and we might add it later if we have a use for it

    • @allenhu9987
      @allenhu9987 5 лет назад

      @@bawad
      Please tell me the first one.

    • @bawad
      @bawad  5 лет назад

      What?

    • @allenhu9987
      @allenhu9987 5 лет назад

      @@bawad if You associate react & react native with lerna please tell me the first one

    • @bawad
      @bawad  5 лет назад

      Yeah you can use react and react native with lerna

  • @Chiavaccio
    @Chiavaccio 5 лет назад

    Cool! ☺☺

  • @MrDevianceh
    @MrDevianceh 5 лет назад

    Can you make a series about nodejs projects on zeits now? I keep hitting walls and their documentation is abysmal

    • @bawad
      @bawad  5 лет назад

      I'll probably deploy to zeit now sometime