@react-native/babel-preset 从 react-native 导入的模块不是延迟导入(lazy requires),

r7xajy2e  于 5个月前  发布在  React
关注(0)|答案(1)|浏览(126)

描述

Failing test repro
@react-native/babel-preset 的预期行为是在它们首次被引用的作用域内推迟一部分 react-native 模块的评估:https://github.com/facebook/react-native/blob/main/packages/react-native-babel-preset/src/configs/main.js#L76
这种情况不再发生(因为 @babel/plugin-transform-modules-commonjs 将源字符串传递给 lazy 回调,而不是预期的 import specifier)。参见测试 2。

重现步骤

git clone git@github.com:stevoland/RNTest.git
git checkout lazy-imports-repro
yarn
yarn test babel.test

React Native 版本

0.73.4

受影响的平台

运行时 - Android,运行时 - iOS

npx react-native info 的输出

System:
  OS: macOS 14.1
  CPU: (12) arm64 Apple M2 Pro
  Memory: 898.08 MB / 32.00 GB
  Shell:
    version: 3.2.57
    path: /bin/bash
Binaries:
  Node:
    version: 18.18.0
    path: ~/.nvm/versions/node/v18.18.0/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v18.18.0/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.0/bin/npm
  Watchman:
    version: 2024.04.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /usr/local/bin/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: 2021.1 AI-211.7628.21.2111.8309675
  Xcode:
    version: 15.0/15A240d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.3
    path: /Users/stephen.collings/.sdkman/candidates/java/current/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.4
    wanted: 0.73.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

堆栈跟踪或日志

FAIL  __tests__/lazy-imports.test.ts
  ✕ should defer select react-native imports (403 ms)
  ✓ should defer all imports (26 ms)

  ● should defer select react-native imports

    expect(received).toMatchInlineSnapshot(snapshot)

    Snapshot name: `should defer select react-native imports 1`

    - Snapshot  - 1
    + Received  + 1

    - "function _reactNative(){var data=require("react-native");_reactNative=function _reactNative(){return data;};return data;}var a=function a(){return _reactNative().AccessibilityInfo;};"
    + "var _reactNative=require("react-native");var a=function a(){return _reactNative.AccessibilityInfo;};"

      17 | const a = () => AccessibilityInfo`;
      18 |
    > 19 |   expect(transform(input)).toMatchInlineSnapshot(
         |                            ^
      20 |     `"function _reactNative(){var data=require("react-native");_reactNative=function _reactNative(){return data;};return data;}var a=function a(){return _reactNative().AccessibilityInfo;};"`,
      21 |   );
      22 | });

      at Object.toMatchInlineSnapshot (__tests__/lazy-imports.test.ts:19:28)

重现者

stevoland/RNTest@02effcb

截图和视频

  • 无响应*
wgx48brx

wgx48brx1#

⚠️React Native的新版本可用!
i️您正在使用受支持的次要版本,但似乎有一个更新的补丁可用 - 0.73.8。请升级到您次要版本的最高补丁或最新版本,并验证问题是否仍然存在(或者,创建一个新项目并在其中重现问题)。如果无法重现,请告知我们,以便我们关闭此问题。这有助于确保我们关注仍在最近版本中存在的问题。

相关问题