Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.76] Error: Cannot find module '@react-native-community/cli-server-api' #47309

Open
Tracked by #2131
tido64 opened this issue Oct 30, 2024 · 4 comments · May be fixed by #49325
Open
Tracked by #2131

[0.76] Error: Cannot find module '@react-native-community/cli-server-api' #47309

tido64 opened this issue Oct 30, 2024 · 4 comments · May be fixed by #49325
Assignees
Labels
0.76 Never gets stale Prevent those issues and PRs from getting stale p: Microsoft Partner: Microsoft Partner

Comments

@tido64
Copy link
Collaborator

tido64 commented Oct 30, 2024

Description

react-native bundle and react-native start are currently not correctly registered. After some investigation, this is what's happening:

  • @react-native/community-cli-plugin requires @react-native-community/cli-server-api to register commands like bundle and start
  • However, the former declares it as a peer dependency and also making it optional:
    "devDependencies": {
    "metro-resolver": "^0.81.0"
    },
    "peerDependencies": {
    "@react-native-community/cli-server-api": "*"
    },
  • The responsibility to fulfill the requirement falls on whoever consumes @react-native/community-cli-plugin, which in this case is react-native. But react-native does not declare dependency on @react-native-community/cli-server-api. And since it's marked as optional, package managers don't complain.
  • Failing to load @react-native-community/cli-server-api means that bundle and start never gets registered and won't show up in config.

One way to fix this is to make @react-native-community/cli-server-api required again, and forward that dependency in react-native. This should make the consumer the responsible for satisfying the dependency. This also means that the template needs to be updated to include this dependency. I'm sure there are other alternatives that I have overlooked.

An alternative to that would be to make @react-native/community-cli-plugin or react-native directly depend on @react-native/community-cli-plugin.

A third option would be to move the package to the RN repo and make it part of @react-native/community-cli-plugin

Steps to reproduce

  1. Clone/check out this branch: chore: bump react-native to 0.76 microsoft/rnx-kit#3409
  2. Remove workarounds in .yarnrc.yml (the react-native section under resolutions)
  3. Run yarn
  4. Apply the following fixes directly under packages/test-app/node_modules/:
  5. Run react-native config inside packages/test-app
  6. Verify that bundle and start are missing

React Native Version

0.76.1

Affected Platforms

Build - MacOS, Build - Windows, Build - Linux

Output of npx react-native info

System:
  OS: macOS 14.7
  CPU: (10) arm64 Apple M1 Max
  Memory: 1.54 GB / 64.00 GB
  Shell:
    version: 3.7.1
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 20.18.0
    path: /private/var/folders/j0/5zfnwvyd4sb15smylklx03m00000gn/T/xfs-27033e9b/node
  Yarn:
    version: 4.4.0
    path: /private/var/folders/j0/5zfnwvyd4sb15smylklx03m00000gn/T/xfs-27033e9b/yarn
  npm:
    version: 10.8.2
    path: ~/.local/bin/npm
  Watchman:
    version: 2024.09.30.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/tido/.gem/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK:
    API Levels:
      - "34"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-34 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 3.3.5
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0
    wanted: ^15.0.0
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.1
    wanted: ^0.76.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

Error: Cannot find module '@react-native-community/cli-server-api'
  Require stack:
  - /~/node_modules/.store/@react-native-community-cli-plugin-virtual-29d9c8df52/package/dist/commands/start/runServer.js
  - /~/node_modules/.store/@react-native-community-cli-plugin-virtual-29d9c8df52/package/dist/commands/start/index.js
  - /~/node_modules/.store/@react-native-community-cli-plugin-virtual-29d9c8df52/package/dist/index.js
  - /~/node_modules/.store/react-native-virtual-5d869b466d/package/react-native.config.js
  - /~/node_modules/.store/cosmiconfig-virtual-f7d5522c5c/package/dist/loaders.js
  - /~/node_modules/.store/cosmiconfig-virtual-f7d5522c5c/package/dist/defaults.js
  - /~/node_modules/.store/cosmiconfig-virtual-f7d5522c5c/package/dist/index.js
  - /~/node_modules/.store/@react-native-community-cli-config-npm-15.0.0-1758a65588/package/build/readConfigFromDisk.js
  - /~/node_modules/.store/@react-native-community-cli-config-npm-15.0.0-1758a65588/package/build/loadConfig.js
  - /~/node_modules/.store/@react-native-community-cli-config-npm-15.0.0-1758a65588/package/build/index.js
  - /~/node_modules/.store/@react-native-community-cli-npm-15.0.0-2240e43604/package/build/commands/index.js
  - /~/node_modules/.store/@react-native-community-cli-npm-15.0.0-2240e43604/package/build/index.js
  - /~/node_modules/.store/react-native-virtual-5d869b466d/package/cli.js

Reproducer

microsoft/rnx-kit#3409

Screenshots and Videos

No response

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Oct 30, 2024
@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ 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
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:

@react-native-bot
Copy link
Collaborator

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

@react-native-bot react-native-bot added Stale There has been a lack of activity on this issue and it may be closed soon. and removed Stale There has been a lack of activity on this issue and it may be closed soon. labels Nov 30, 2024
@blakef blakef added Never gets stale Prevent those issues and PRs from getting stale and removed Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Dec 1, 2024
@avishekdev
Copy link

Facing this same issue when building my expo app in production mode using the EAS build command.

tido64 added a commit to tido64/react-native-template that referenced this issue Feb 12, 2025
facebook-github-bot pushed a commit that referenced this issue Feb 19, 2025
Summary:
`react-native/community-cli-plugin` depends on `createDevServerMiddleware` from `react-native-community/cli-server-api`. 

`react-native/community-cli-plugin` currently [declares an optional peer dependency](https://github.com/facebook/react-native/blob/bae895500052bda2f55e1832b0c8a63a1b449de3/packages/community-cli-plugin/package.json#L39-L45) on `react-native-community/cli-server-api`, however because the latter isn't a dependency of `react-native` or the community template, the peer dependency is not available to package managers that enforce isolated node_modules - see #47309.

Rather than add an unnecessary dependency to the template (like [this](react-native-community/template#105)), my proposal is to switch to a peer dependency on only `react-native-community/cli`, because that *is* a dependency of the community template and therefore will be resolvable.

Because `react-native-community/cli` doesn't re-export `createDevServerMiddleware` from its dependency on `cli-server-api`, we need to resolve the latter through the former. This can be cleaned up once a re-export lands - react-native-community/cli#2605.

Changelog:
[GENERAL][FIXED] Fix registering of `start` and `bundle` commands with community CLI and isolated node_modules.

Differential Revision: D69848688
facebook-github-bot pushed a commit that referenced this issue Feb 19, 2025
…li (#49518)

Summary:
Pull Request resolved: #49518

`react-native/community-cli-plugin` depends on `createDevServerMiddleware` from `react-native-community/cli-server-api`.

`react-native/community-cli-plugin` currently [declares an optional peer dependency](https://github.com/facebook/react-native/blob/bae895500052bda2f55e1832b0c8a63a1b449de3/packages/community-cli-plugin/package.json#L39-L45) on `react-native-community/cli-server-api`, however because the latter isn't a dependency of `react-native` or the community template, the peer dependency is not available to package managers that enforce isolated node_modules - see #47309.

Rather than add an unnecessary dependency to the template (like [this](react-native-community/template#105)), my proposal is to switch to a peer dependency on only `react-native-community/cli`, because that *is* a dependency of the community template and therefore will be resolvable.

Because `react-native-community/cli` doesn't re-export `createDevServerMiddleware` from its dependency on `cli-server-api`, we need to resolve the latter through the former. This can be cleaned up once a re-export lands - react-native-community/cli#2605.

Changelog:
[GENERAL][FIXED] Fix registering of `start` and `bundle` commands with community CLI and isolated node_modules.

Reviewed By: huntie

Differential Revision: D69848688

fbshipit-source-id: 009b8ffd43b2ab2d84fcc71e9e48382eb8950bb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.76 Never gets stale Prevent those issues and PRs from getting stale p: Microsoft Partner: Microsoft Partner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants