Autolinking.json breaks whenever console.log is added to react-native.config.js
Environment
System: OS: macOS 15.5 CPU: (12) arm64 Apple M4 Pro Memory: 58.73 MB / 24.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 24.0.0 path: ~/.nvm/versions/node/v24.0.0/bin/node Yarn: version: 1.22.22 path: ~/.nvm/versions/node/v24.0.0/bin/yarn npm: version: 11.3.0 path: ~/.nvm/versions/node/v24.0.0/bin/npm Watchman: Not Found Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: - DriverKit 24.4 - iOS 18.4 - macOS 15.4 - tvOS 18.4 - visionOS 2.4 - watchOS 11.4 Android SDK: API Levels: - "34" - "35" Build Tools: - 34.0.0 - 35.0.0 - 35.0.1 - 36.0.0 System Images: - android-36 | Google APIs ARM 64 v8a - android-36 | Google Play ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2024.3 AI-243.25659.59.2432.13423653 Xcode: version: 16.3/16E140 path: /usr/bin/xcodebuild Languages: Java: version: 17.0.15 path: /usr/bin/javac Ruby: version: 3.2.0 path: /Users/riteshshukla/.rvm/rubies/ruby-3.2.0/bin/ruby npmPackages: "@react-native-community/cli": installed: 19.0.0 wanted: 19.0.0 react: installed: 19.1.0 wanted: 19.1.0 react-native: installed: 0.80.0 wanted: 0.80.0 react-native-macos: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: true iOS: hermesEnabled: Not found newArchEnabled: false
Description
So I noticed this bug
Whenever I have a console.log in my react-native.config.js . The same is logged when npx @react-native-community/cli config runs (which is expected) in terminal .
But since the same command is used to generate autoLinking.json . The log is present in autoLinking.json making the json file invalid
Reproducible Demo
React native config.json (Notice the console log on top)
Autolinking.json(Notice the top) . Invalid Json
Solution
I vibe coded this . Adding a supress console whenever config runs
Something like this
function suppressConsole() {
const originalMethods = {
log: console.log,
warn: console.warn,
error: console.error,
info: console.info,
debug: console.debug,
};
// Override console methods with empty functions
console.log = () => {};
console.warn = () => {};
console.error = () => {};
console.info = () => {};
console.debug = () => {};
return () => {
// Restore original console methods
console.log = originalMethods.log;
console.warn = originalMethods.warn;
console.error = originalMethods.error;
console.info = originalMethods.info;
console.debug = originalMethods.debug;
};
}