描述
由于某种原因,在我们的项目中,运行时react-native代码使用了pretty-format
v29,而代码期望的是v26。一位同事通过使用下面的补丁解决了这个问题,但在我们的项目中,将package.json
指定为版本26也起到了作用。
在我们的项目中,我发现Jest使用了pretty-format
v29,这无疑与此有关。我没有调查根本原因,而是认为升级pretty-format
会更有利。因此,我为此问题提交了这个issue;参见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,
重现步骤
执行一个类似于console.log('index.native.js', { myObject: 'myvalue' });
的操作,没有任何输出
执行console.log('index.native.js')
操作,有输出
React Native版本
0.73.9
受影响的平台
运行时 - Android,运行时 - iOS
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
堆栈跟踪或日志
None
可复现问题
https://github.com/facebook/react-native/pull/45732/files
截图和视频
- 无响应*
2条答案
按热度按时间cuxqih211#
nnvyjq4y2#