Git Product home page Git Product logo

Comments (9)

davidseek avatar davidseek commented on May 26, 2024 1

Adding this default react-native.config.js to packageB root also resolved the issue.

from cli.

davidseek avatar davidseek commented on May 26, 2024

PS, I found @react-native/community-cli-plugin, which seems to carry the bundle command and is marked as "Formerly @react-native-community/cli-plugin-metro".

But the usage leads me back to my original issue:

npx react-native bundle --entry-file <path> [options]

from cli.

szymonrybczak avatar szymonrybczak commented on May 26, 2024

hey @davidseek! that's strange these commands should be added by Core thanks to @react-native/community-cli-plugin, please make sure that you have proper react-native version, and also do you mind running npx react-native config?

from cli.

davidseek avatar davidseek commented on May 26, 2024

Thanks for getting back to me. The problem seems to be the following:

My workspace has 2 npm packages.

  • Package A contains all node_modules, aka 3p dependencies
  • Package B is my Manifest, it syncs the node_modules from Package A

Running bundle command from Package A works.

Package A -> node node_modules/react-native/local-cli/cli.js bundle
                Welcome to Metro v0.80.4
              Fast - Scalable - Integrated

Running bundle command from Package B does not work.

Package B -> node node_modules/react-native/local-cli/cli.js bundle
error: unknown command 'bundle'

Even when I try to call the script from Package A from within Package B it also throws the same issue.

Package B -> node ../Package A/node_modules/react-native/local-cli/cli.js bundle 
error: unknown command 'bundle'

Only works if I call it directly from the root of Package A.

Package A -> node node_modules/react-native/local-cli/cli.js bundle
                Welcome to Metro v0.80.4
              Fast - Scalable - Integrated

node_modules of both packages are in sync. I understand that you're not exactly supporting custom setups, but any clue why Package A can find the bundle info from within @react-native, as you described, but Package B can't?

from cli.

szymonrybczak avatar szymonrybczak commented on May 26, 2024
  1. Does running commands via npx react-native change something?
  2. Could you please confirm if the config return from npx react-native config command from package A is the same as from package B? If not, what's the difference?

from cli.

davidseek avatar davidseek commented on May 26, 2024
  • npx react-native works in Package A, just like calling cli.js bundle directly
  • npx react-native in Package B leads to unknown command 'bundle'

Package B npx react-native config output:

{
  "root": "/Volumes/workplace/Package B",
  "reactNativePath": "/Volumes/workplace/Package B/node_modules/react-native",
  "reactNativeVersion": "0.73",
  "dependencies": {},
  "commands": [],
  "healthChecks": [],
  "platforms": {},
  "project": {}
}

Package A npx react-native config output shows a WHOLE LOT MORE, and also contains the bundle command.

"root": "/Volumes/workplace/Package A",
"reactNativePath": "/Volumes/workplace/Package A/node_modules/react-native",
"reactNativeVersion": "0.73",
....
"commands": [
{ "name": "bundle",
      "description": "Build the bundle for the provided JavaScript entry file.",
      "options": [
        {
          "name": "--entry-file <path>",
          "description": "Path to the root JS file, either absolute or relative to JS root"
        },
        {
        
...
            
"healthChecks": [],
"platforms": {
    "ios": {},
    "android": {}
  },
"project": {
    "ios": null,
    "android": null
  }

How can I sync this info from Package A to Package B?

from cli.

SemihGk avatar SemihGk commented on May 26, 2024

I have the same issue :error: unknown command 'bundle' . I am also on the process of upgrading from 0.69 to 0.73. After debugging @react-native-community/cli and @react-native-community/cli-config libraries, It looks like your metro.config.js file should be under same level of node_modules/@react-native-community/cli** folders

Have the following monorepo folder structure:

apps/
     - mobile/
        -- metro.config.js
        -- react-native.js
node_modules/
      - @react-native-community/
         -- cli/
         -- cli-config/   

Eventually,I had to create symlinks to the config files folder in order to resolve the issue.

ln -snf node_modules/@react-native-community apps/mobile/node_modules
ln -snf node_modules/react-native apps/mobile/node_modules

Obviously, this cannot be a desired solution. Hopefully, we can find a better solution. It is an annoying issue indeed.

from cli.

davidseek avatar davidseek commented on May 26, 2024

We have the following structure

packageA/
    - node_nodules (original)
packageB/
    - node_nodules (symlink of packageA/node_nodules)
    - script for bundle creation
    - metro config etc

We used to call the script for bundle creation from packageB root. This throws now unknown command 'bundle'. I'm able to call the same underlying command, equivalent to npx react-native bundle ... from packageA and it works. But all my Configs and sources are in packageB. Metro config missing etc.

Symlinking the node_nodules content as you did above @SemihGk wouldn't solve my issue. Because we're already doing that. I need to be able to call npx react-native bundle ... from packageB.

from cli.

davidseek avatar davidseek commented on May 26, 2024

I found a way to bypass my issue. The key is, that packageB has no direct dependencies. packageA is the 3p dependencies repo which other packages symlink from.

In order to use the bundle command, we had to add react-native as a dependency within packageB.

Without running yarn install or npm install, npx react-native bundle works now as expected.

For us the key is not to actually have direct dependencies outside of packageA.

Therefore I'm using a small script to add the dependency right before we build the bundle.

// Pseudo
const json = await fs.readFile('package.json)
json.dependencies = { "react-native": "^0.73.2" }
await fs.writeFile('package.json, json)

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.