-
Notifications
You must be signed in to change notification settings - Fork 929
Description
Environment
node: v24.7.0
OS: macOS 15.6.1
Description
When running
npx @react-native-community/cli@latest init AwesomeProject
I get the following error:
error Invalid Version: latest.
TypeError: Invalid Version: latest
at new SemVer (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/semver/classes/semver.js:40:13)
at compare (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/semver/functions/compare.js:5:3)
at Object.lt (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/semver/functions/lt.js:4:29)
at createTemplateUri (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/version.js:44:47)
at createProject (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/init.js:354:60)
at Object.initialize [as func] (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/commands/init/init.js:434:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Command.handleAction (/Users/[user]/.npm/_npx/2788f5fbd47acb89/node_modules/@react-native-community/cli/build/index.js:137:9)
I am in a corporate environment that has a third-party registry set up, and has explicitly blocked the standard npmjs registry. This third-party registry also requires authentication. We set this up with the npm login command, which initializes our ~/.npmrc file to look like this:
registry=https://example.com/api/npm/npm
//example.com/api/npm/npm/:_authToken=BIGAUTHTOKEN
I have isolated the issue to this line:
cli/packages/cli/src/tools/npm.ts
Line 64 in ddbba6c
| const resp = await fetch(url); |
Essentially we assume that the registry does not require authentication, and can just fetch information from it via the URL.
Proposed solution: The _authToken config is one of the few that you cannot just extract with npm config get, due to it's sensitive nature. Instead we could add the token as an optional parameter, e.g.
npx @react-native-community/cli@latest init AwesomeProject --auth-token=BIGAUTHTOKEN
And update the fetch code to look something like this:
...
const headers = authToken ? { Authorization: `Bearer ${authToken}` } : undefined
const resp = await fetch(url, { headers });