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

Warnings emitted on init when ran from within a non-installed package #1493

Open
kraenhansen opened this issue Nov 4, 2021 · 6 comments
Open
Labels
bug report no-stale-bot This issue cannot be marked as stale by stale bot

Comments

@kraenhansen
Copy link
Contributor

Environment

System:
    OS: macOS 11.6
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 983.04 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    Yarn: 1.22.11 - ~/.nvm/versions/node/v14.16.0/bin/yarn
    npm: 7.19.1 - ~/.nvm/versions/node/v14.16.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
    Android SDK:
      Android NDK: 21.0.6113669
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7784292
    Xcode: 13.0/13A233 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/local/opt/openjdk@11/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Description

I want to react-native init a new app while my current working directory is a (a sub-directory of) another package.
But when I do this from within a package that has not yet been installed (or linked in the case of a Lerna mono-repo), the CLI emits confusing warnings (see example below).

I believe the root cause of these warnings is that an attempt is made to locate a root package and load its configuration (https://github.com/react-native-community/cli/blob/master/packages/cli/src/index.ts#L217) independently on what command is being executed.

The default behaviour of loadConfig is to find the nearest package.json up the tree: https://github.com/react-native-community/cli/blob/master/packages/cli/src/tools/config/index.ts#L61 which will find the enclosing package with uninstalled dependencies.

Ideally running react-native init shouldn't traverse my file system to determine a configuration.
Most likely the commands meant to be executed "detached" from a package, should have an early return code-path to make sure the configuration is never loaded when running those.

Reproducible Demo

# Create a package
cat << EOF > package.json
{
  "name": "wrong-root-package",
  "dependencies": {
    "unresolvable-package": "^1.0.0"
  }
}
EOF

# Try running the "react-native" CLI to initialize a new app
npx --yes react-native init MyTestApp

When running this, notice the warning emitted from the CLI:

warn Package unresolvable-package has been ignored because it contains invalid configuration. Reason: Cannot find module 'unresolvable-package/package.json'
Require stack:
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/tools/config/resolveNodeModuleDir.js
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/tools/releaseChecker/index.js
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/start/runServer.js
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/start/start.js
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/index.js
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/index.js
- /Users/kraen.hansen/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/bin.js

Workaround

Users can place a package.json containing an empty object ({}) in the current working directory before executing the react-native init command.

@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Nov 26, 2022
@kraenhansen
Copy link
Contributor Author

This is still an issue.

@thymikee thymikee removed the stale label Nov 26, 2022
@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label Feb 25, 2023
@kraenhansen
Copy link
Contributor Author

This is still an issue.

@github-actions github-actions bot removed the stale label Feb 26, 2023
@github-actions
Copy link

There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

@github-actions github-actions bot added the stale label May 28, 2023
@kraenhansen
Copy link
Contributor Author

This is still an issue.

@szymonrybczak szymonrybczak added no-stale-bot This issue cannot be marked as stale by stale bot and removed stale labels May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report no-stale-bot This issue cannot be marked as stale by stale bot
Projects
None yet
Development

No branches or pull requests

3 participants