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
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
.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