facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.05k stars 24.32k forks source link

The commander dependency is missing in the react-native package #46149

Closed Daniel3711997 closed 1 month ago

Daniel3711997 commented 2 months ago

Description

The commander dependency is missing in the react-native package which causes the iOS release builds to fail with program.version is not a function after installing packages that uses a higher version of the commander package.

Steps to reproduce

  1. Create a new application with: npx @react-native-community/cli@latest init AwesomeProject
  2. Run: npm install --save-dev cspell lint-staged
  3. Remove the package-json.lock file & node_nodules folder
  4. Run: npm install
  5. Run: node ./node_modules/react-native/scripts/bundle.js --config-cmd '' --entry-file index.js --platform ios --dev false --reset-cache --bundle-output ./main.jsbundle --assets-dest ./assets --minify false --config-cmd 'node ./node_modules/react-native/cli.js config'

React Native Version

0.75.2

Affected Platforms

Runtime - iOS

Output of npx react-native info

❯ npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 14.6.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 481.47 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.16.0
    path: ~/.nvm/versions/node/v20.16.0/bin/node
  Yarn: Not Found
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v20.16.0/bin/npm
  Watchman:
    version: 2024.08.19.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/user/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 33.0.0
      - 34.0.0
    System Images:
      - android-33 | ARM 64 v8a
      - android-33 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12169540
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /Users/user/.sdkman/candidates/java/current/bin/javac
  Ruby:
    version: 2.7.5
    path: /Users/user/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

❯ node ./node_modules/react-native/scripts/bundle.js --config-cmd '' --entry-file index.js --platform ios --dev false --reset-cache --bundle-output ./main.jsbundle --assets-dest ./assets --minify false --config-cmd 'node ./node_modules/react-native/cli.js config'
/Users/user/Desktop/AwesomeProject/node_modules/react-native/scripts/bundle.js:19
program.version(
        ^

TypeError: program.version is not a function
    at Object.<anonymous> (/Users/user/Desktop/AwesomeProject/node_modules/react-native/scripts/bundle.js:19:9)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.16.0

Reproducer

Just follow the Steps to reproduce

Screenshots and Videos

No response

react-native-bot commented 2 months ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
react-native-bot commented 2 months ago
:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
jeremiebardon commented 2 months ago

Same issue here, unable to build the release app on iOS

Daniel3711997 commented 2 months ago

Same issue here, unable to build the release app on iOS

Just install 'commander' and it will work, if this does not help remove package-lock.json and node_modules and install it again. :)

jeremiebardon commented 2 months ago

Just install 'commander' and it will work, if this does not help remove package-lock.json and node_modules and install it > > again. :)

Oh ok! Thank you for the heads up, I will try that :)

TiKevin83 commented 2 months ago

Same issue here, unable to build the release app on iOS

Just install 'commander' and it will work, if this does not help remove package-lock.json and node_modules and install it again. :)

I tried this and it failed with a different error once, a file was missing node_modules/react-native/React/Fabric/RCTThirdPartyFabricComponentsProvider.h. I then reinstalled pods and afterward commander was missing again at node_modules/react-native/scripts/bundle.js:19.

blakef commented 2 months ago

TL;DR: I agree that we need to explicitly add commander as a dependency for react-native. I'd prefer to refactor the bundle.js script to remove it entirely (as we have too many different versions of it in the react-native repo) as users for the most part don't interact with this directly.

Mitigation:

If you are being affected by this, you can unblock yourself for now by:

npm install -D commander@11.1.0

Reproducing

I couldn't reproduce this using the steps provided, because commander@2.20.3 and 9.5.0 were transitively pulled in:

➜  AwesomeProject git:(main) ✗ npm why commander
commander@9.5.0
node_modules/commander
  commander@"^9.4.1" from @react-native-community/cli@14.0.0
  node_modules/@react-native-community/cli
    @react-native-community/cli@"14.0.0" from react-native@0.75.2
    node_modules/react-native
      react-native@"0.75.2" from the root project
      peer react-native@"*" from @react-native/virtualized-lists@0.75.2
      node_modules/@react-native/virtualized-lists
        @react-native/virtualized-lists@"0.75.2" from react-native@0.75.2

commander@2.20.3
node_modules/terser/node_modules/commander
  commander@"^2.20.0" from terser@5.31.6
  node_modules/terser
    terser@"^5.15.0" from metro-minify-terser@0.80.10
    node_modules/metro-minify-terser
      metro-minify-terser@"0.80.10" from metro-transform-worker@0.80.10
      node_modules/metro-transform-worker
        metro-transform-worker@"0.80.10" from metro@0.80.10
        node_modules/metro
          metro@"0.80.10" from metro-config@0.80.10
          node_modules/metro-config
            metro-config@"0.80.10" from metro@0.80.10
            metro-config@"^0.80.3" from @react-native/community-cli-plugin@0.75.2
            node_modules/@react-native/community-cli-plugin
              @react-native/community-cli-plugin@"0.75.2" from react-native@0.75.2
              node_modules/react-native
                react-native@"0.75.2" from the root project
                peer react-native@"*" from @react-native/virtualized-lists@0.75.2
                node_modules/@react-native/virtualized-lists
                  @react-native/virtualized-lists@"0.75.2" from react-native@0.75.2
            metro-config@"^0.80.3" from @react-native/metro-config@0.75.2
            node_modules/@react-native/metro-config
              dev @react-native/metro-config@"0.75.2" from the root project
          metro@"0.80.10" from metro-transform-worker@0.80.10
          metro@"^0.80.3" from @react-native/community-cli-plugin@0.75.2
          node_modules/@react-native/community-cli-plugin
            @react-native/community-cli-plugin@"0.75.2" from react-native@0.75.2
            node_modules/react-native
              react-native@"0.75.2" from the root project
              peer react-native@"*" from @react-native/virtualized-lists@0.75.2
              node_modules/@react-native/virtualized-lists
                @react-native/virtualized-lists@"0.75.2" from react-native@0.75.2
c100k commented 1 month ago

Hey, Solved by https://github.com/facebook/react-native/commit/9f3fe8178f91a6fef6ccd27db301eaddbe12f0f3 I guess ? Do you know when 0.75.3 is planned ?

blakef commented 1 month ago

Early next week.

c100k commented 1 month ago

Nice ! In any case, thanks for your quick fix and the proposed workaround, which does the job in the meantime.