Skip to content

Unable to initialize project with third-party registry that requires authenticationΒ #2718

@rliljest

Description

@rliljest

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:

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 });

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions