react / react/react-native

TypeError: Cannot read property 'OS' of undefined in Libraries/Settings/Settings.js due to circular dependency on startup

Đang mở
#56,967 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

API: Settings Needs: Triage :mag:
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

Description

When launching React Native applications with specific initialization/module loading sequences (such as during the boot of Expo host apps), the app crashes on startup with the following error:

[runtime not ready]: TypeError: Cannot read property 'OS' of undefined
Steps to reproduce

A minimal reproduction repository is available at Capstan/reproducer-react-native-settings on branch repro/settings-circular-dependency.

You can clone it, checkout the branch, and run:

yarn install
yarn test

Alternatively, you can minimally reproduce this crash by placing the following Jest unit test inside packages/react-native/Libraries/Settings/__tests__/Settings-test.js and running it:

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow strict-local
 * @format
 * @oncall react_native
 */

'use strict';

describe('Settings', () => {
  beforeEach(() => {
    jest.resetModules();
  });

  it('should not throw due to circular dependency during Platform initialization', () => {
    // Intercept NativePlatformConstantsIOS (which Platform.ios requires during load)
    // to simulate another module requiring Settings during Platform's initialization phase.
    jest.mock('../../Utilities/NativePlatformConstantsIOS', () => {
      // Accessing Settings while Platform is loading
      require('../Settings.js');
      return {
        getConstants() {
          return {
            interfaceIdiom: 'phone',
            isTesting: true,
            osVersion: '16.0',
            systemName: 'iOS',
          };
        },
      };
    });

    expect(() => {
      require('../../Utilities/Platform');
    }).not.toThrow();
  });
});
React Native Version

0.85.3

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.5
  CPU: (10) arm64 Apple M1 Max
  Memory: 2.55 GB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 26.0.0
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 11.12.1
    path: /opt/homebrew/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/lib/ruby/gems/4.0.0/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.5
      - iOS 26.5
      - macOS 26.5
      - tvOS 26.5
      - visionOS 26.5
      - watchOS 26.5
  Android SDK:
    API Levels:
      - "36"
      - "36"
    Build Tools:
      - 35.0.0
      - 36.0.0
      - 36.1.0
      - 37.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.3 AI-253.32098.37.2534.15336583
  Xcode:
    version: 26.5/17F42
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 26.0.1
    path: /opt/homebrew/opt/openjdk/bin/javac
  Ruby:
    version: 4.0.5
    path: /opt/homebrew/opt/ruby/bin/ruby
Stacktrace or Logs
Error name:    "TypeError"
Error message: "Cannot read properties of undefined (reading 'OS')"

  at Object.OS (node_modules/react-native/Libraries/Settings/Settings.js:21:14)
  at require (__tests__/SettingsCircularDependency.test.ts:17:7)
  at Object.require (node_modules/react-native/Libraries/Utilities/Platform.ios.js:13:1)
MANDATORY Reproducer

https://github.com/Capstan/reproducer-react-native-settings/tree/repro/settings-circular-dependency

Screenshots and Videos

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với Libraries/Settings/Settings.js và Utilities/Platform.ios.js, sau đó chạy reproducer trên branch repro/settings-circular-dependency bằng yarn install và yarn test. Settings circular-dependency test hiện có sẽ phải chạy thành công mà không xảy ra lỗi crash khi khởi tạo Platform hoặc TypeError do OS chưa được định nghĩa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, react-native
Lĩnh vực
mobile
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
68/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.