cli icon indicating copy to clipboard operation
cli copied to clipboard

fix: Remove hardcoded npm registry url

Open jasonjiicloud opened this issue 1 year ago • 1 comments

Summary:

fixes: #2519 Official npm registry url is hardcoded, the "cli" can't run successfully in a closed environment.

Following error is displayed when running npx @react-native-community/cli@latest init AwesomeProject --verbose.

error fetch failed.
TypeError: fetch failed
    at node:internal/deps/undici/undici:13178:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getTemplateVersion (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/tools/npm.js:121:16)
    at async createTemplateUri (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/version.js:53:29)
    at async createProject (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/init.js:341:23)
    at async Object.initialize [as func] (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/init.js:422:7)
    at async Command.handleAction (/Users/jilingyun/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/index.js:116:9)

My solution is using getNpmRegistryUrl() to get real npm registry url in user's local environment, then it can avoid using official npm registry directly.

Test Plan:

Build and run node /path/to/react-native-cli/packages/cli/build/bin.js init AwesomeProject

Checklist

  • [ ] Documentation is up to date to reflect these changes.
  • [ ] Follows commit message convention described in CONTRIBUTING.md

jasonjiicloud avatar Oct 06 '24 09:10 jasonjiicloud

cc @blakef

szymonrybczak avatar Oct 07 '24 10:10 szymonrybczak

There hasn't been any activity on this pull request 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[bot] avatar Feb 04 '25 03:02 github-actions[bot]