react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Is it ok to use optionalDependencies to avoid auto-linking?

Open Invertisment opened this issue 3 years ago • 0 comments

Description

This is more of a question than a bug because I actually want the current behavior. But if it changes then I'll be in a bad situation. So as it's undocumented I want to write an issue and ask about it.

I was migrating my app out of expo and I think I finally (oh my it was a bad experience) found a configuration that allows web to run via expo but native apps run without it.

If I add expo into optionalDependencies field of package.json then it doesn't try to link automatically and that's what I want.

I want to know if it's intended and if I can use it. And if I shouldn't use optionalDependencies then maybe could you suggest a better way?

Also these metro blacklists and exclusions didn't work: https://github.com/facebook/react-native/issues/31215 https://stackoverflow.com/questions/41813211/how-to-make-metro-react-native-packager-ignore-certain-directories/41963217#41963217 I think that linking exclusion has to be done in the package.json because then gradle can't pick up and do anything with packages. It's gradle android build that fails when I include expo, not JS bundler.

Version

0.69.4

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: Linux 5.18 Manjaro Linux
    CPU: (16) x64 AMD Ryzen 9 5900HX with Radeon Graphics
    Memory: 16.19 GB / 30.76 GB
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.7.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.17.0 - /usr/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 30, 31, 32, 33
      Build Tools: 29.0.2, 30.0.3, 33.0.0
      System Images: android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: AI-212.5712.43.2112.8815526
  Languages:
    Java: 11.0.16.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.0.0 => 18.0.0 
    react-native: 0.69.4 => 0.69.4 
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Create new project using react-native init
  2. Add expo via yarn add expo
  3. run expo start --web
  4. install missing dependencies (run expo start --web and it will display what it wants; probably just expo webpack config)
  5. try to run react-native run-android and it should fail because expo breaks the build
  6. open package.json and move expo to optionalDependencies
  7. react-native run-android as well as expo start --web should work

Snack, code example, screenshot, or link to a repository

https://github.com/Invertisment/rn-expo-web-no-autolink

If you try to run web and android in the freshly downloaded repo then both will work.

If you move expo to devDependencies or to dependencies then react-native run-android will fail but web will still work.

It would be great if I could use it.

Invertisment avatar Aug 26 '22 06:08 Invertisment