facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.06k stars 24.19k forks source link

Upgrade pretty-format to 29 #45726

Open dprevost-LMI opened 1 month ago

dprevost-LMI commented 1 month ago

Description

For some reason, in our project, at runtime, the react-native code uses the pretty-format v29 while the code expects v26. A colleague fixed that by using the below patch, but specifying version 26 in our package.json also does the job.

In our project, I saw that Jest uses pretty-format v29, which is undoubtedly somehow related.

Instead of investigating the root cause, I thought upgrading pretty-format would be more beneficial. So, I'm entering this issue for that; see this PR.

diff --git a/node_modules/react-native/Libraries/Utilities/HMRClient.js b/node_modules/react-native/Libraries/Utilities/HMRClient.js
index 03ae287..7f3fd21 100644
--- a/node_modules/react-native/Libraries/Utilities/HMRClient.js
+++ b/node_modules/react-native/Libraries/Utilities/HMRClient.js
@@ -124,7 +124,13 @@ const HMRClient: HMRClientNativeInterface = {
           data: data.map(item =>
             typeof item === 'string'
               ? item
-              : prettyFormat(item, {
+              /* 
+                https://jira.ops.expertcity.com/browse/GTCMOB-5830
+                fix for console.log that stopped working after RN 71
+                the require for prettyFormat is importing the wrong version (high major version which has the breaking change)
+                in this package it should be ^26 but it is pulling ^29 
+              */
+              : prettyFormat.format(item, {
                   escapeString: true,
                   highlight: true,
                   maxDepth: 3,

Steps to reproduce

Do a console like console.log('index.native.js', { myObject: 'myvalue' }); and nothing is output Do console.log('index.native.js') and it is output

React Native Version

0.73.9

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

WARNING: You should run npx react-native@latest to ensure you're always using the most current version of the CLI. NPX has cached version (0.73.9) != current release (0.74.3)

info Fetching system and libraries information...
System:
  OS: macOS 14.5
  CPU: (12) arm64 Apple M2 Pro
  Memory: 4.53 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.1
    path: ~/.nvm/versions/node/v18.19.1/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v18.19.1/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/dprevost/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.0
      - iOS 17.0
      - macOS 14.0
      - tvOS 17.0
      - watchOS 10.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.0.1/15A507
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.8
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /Users/dprevost/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native:
    installed: 0.73.9
    wanted: 0.73.9
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

None

Reproducer

https://github.com/facebook/react-native/pull/45732/files

Screenshots and Videos

No response

react-native-bot commented 1 month ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
react-native-bot commented 1 month ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
react-native-bot commented 2 weeks ago

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

dprevost-LMI commented 1 week ago

I link the PR fixing this, should we only keep the PR open and close this issue?

cortinico commented 1 week ago

Upgrade pretty-format to v29 #45732

We can keep it open and will close automatically once the linked PR will merge