rnx-kit icon indicating copy to clipboard operation
rnx-kit copied to clipboard

Cannot read properties of undefined (reading 'platform')

Open ohheyitskartik opened this issue 2 years ago • 3 comments

What happened?

Hi, i have just integrated the rnx bundler into my app but when i run bundler using react-native rnx-start command i get the following error :

Cannot read properties of undefined (reading 'platform') at Object.hook [as experimentalSerializerHook] (/Users/.../node_modules/@rnx-kit/cli/lib/metro-config.js:25:49)

Affected Package

@rnx-kit/cli

Version

0.14.0

Which platforms are you seeing this issue on?

  • [X] Android
  • [X] iOS
  • [ ] macOS
  • [ ] Windows

System Information

System:
    OS: macOS 12.2
    CPU: (8) arm64 Apple M1
    Memory: 169.45 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.3.1 - /usr/local/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
    Android SDK:
      API Levels: 23, 28, 29, 30, 31, 32
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0
      System Images: android-32 | Google APIs ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8193401
    Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.2 => 0.64.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to Reproduce

just integrating to an existing app

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

ohheyitskartik avatar Jun 30 '22 05:06 ohheyitskartik

setting "typescriptValidation": false, in package.json solved the issue

ohheyitskartik avatar Jun 30 '22 06:06 ohheyitskartik

@afoxman, do we need to provide a better error message here? Or not enable typescriptValidation in this scenario?

tido64 avatar Jun 30 '22 07:06 tido64

@afoxman, do we need to provide a better error message here? Or not enable typescriptValidation in this scenario?

I'm guessing this is because of react-native: 0.64.2, which is using Metro < 0.66 which has the serializer-hook fix (adds transformOptions). And so this line is imploding:

const platform = graph.transformOptions.platform as AllPlatforms;

Yes, we should have a more graceful "you are using an unsupported version of Metro" message and then just ignore typescript validation entirely.

Also, peerDependencies may help, though these warnings usually go unnoticed. And docs. README should call out this requirement and CLI should probably sniff it out and warn you on startup. Have to be careful to get package.json using the module path of the loaded copy of Metro to make sure we get the one that they are actually using (avoid hoisting and isolation issues).

afoxman avatar Jun 30 '22 08:06 afoxman