React Native 版本很重要,根據 React Native 的版本號不同,所支援的功能、環境、套件相容性、渲染系統都有所不同,會大大影響後續開發的難易度。所以應去了解手上的版本的內容去設定開發環境的配置。
我整理了以下各版本的更新摘要:
由新版本至舊版本(0.74 ~ 0.60)
React Native 0.74(2024年4月):
align-content: 'space-evenly'
position: 'static': 只有在新架構才支援這個屬性PropTypes
PushNotificationIOS API
React Native 0.73(2023年12月):
console.log() 調用Code > Convert Java file to Kotlin File
@types/react-native
React Native 0.72(2023年6月):
React Native 0.71(2023年1月):
React Native 0.70(2022年9月):
React Native 0.69(2022年6月):
React Native 0.68(2022年3月):
React Native 0.67(2022年1月):
React Native 0.66(2021年10月):
React Native 0.65(2021年8月):
React Native 0.64(2021年3月):
React Native 0.63(2020年7月):
React Native 0.62(2020年3月):
React Native 0.61(2019年9月):
React Native 0.60(2019年7月):
如果你的接手專案低於 0.60 就要再好好考慮一下維護的成本,在升版本或維護的過程會比0.60 以上的版本難度更高,因為沒有 Auto Linking 你需要自己做好依賴與原生模組的連結。
從上面各版更新的內容,我們可以從版本迭代中發現更動的幅度很大,所以在接手專案時,應該根據版號去設置環境,甚至了解該版號支援哪些內容,才可以更快上手,避免在環境建置的時候踩坑。
在終端機輸入:
npx @react-native-community/cli doctor

透過這個指令,它會幫你檢查環境是否相容,並且列出錯誤訊息,當下即可修正。但,即使修正了這些錯誤,你的專案還是開不起來?可能就需要檢查更細節的內容了。
在終端機輸入:
npx react-native info
會取得你目前的專案的環境,他會詳細地列出所有有關這個專案的環境:
info Fetching system and libraries information...
System:
  OS: macOS 13.5.1
  CPU: (10) arm64 Apple M2 Pro
  Memory: 614.67 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 16.19.1
    path: ~/.nvm/versions/node/v16.19.1/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 8.19.3
    path: ~/.nvm/versions/node/v16.19.1/bin/npm
  Watchman:
    version: 2023.07.24.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /Users/ashely/.rvm/gems/ruby-2.7.6/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK:
    API Levels:
      - "27"
      - "28"
      - "30"
      - "33"
      - "33"
      - "34"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
    System Images:
      - android-21 | ARM 64 v8a
      - android-21 | Google APIs ARM 64 v8a
      - android-23 | ARM 64 v8a
      - android-24 | ARM 64 v8a
      - android-26 | ARM 64 v8a
      - android-28 | ARM 64 v8a
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google APIs Intel x86_64 Atom
      - android-34 | Android TV ARM 64 v8a
      - android-34 | Android TV Intel x86 Atom
      - android-34 | Google TV ARM 64 v8a
      - android-34 | Google TV Intel x86 Atom
      - android-34 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 20.0.2
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/ashely/.rvm/rubies/ruby-2.7.6/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
根據筆者經驗,其中有幾個版號需要特別注意的,常常應用程式 build 失敗都跟這些版號設定有關:
通常專案無法編譯,有可能是因為環境與當前 React Native 版本不相容,如果真的建置專案環境時遇到困難,使用 npx react-native info 把你的環境列出來會對於你在社群發問時有幫助的。