Skip to content

[BUG] replace-registry-host doesn't support when two different registries have paths #6110

Closed

Description

@pashakondratyev

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

I have a setup where there may be different registries for example
https://myRegistry.com/a/b/package/-/package-1.1.1.tgz
and
https://myRegistry2.com/a/b/package/-/package-1.1.1.tgz

the first registry would return for the tarball
https://myRegistry.com/a/b/package/-/package-1.1.1.tgz
and if we have replace-registry-host enabled it would replace it like this:
https://myRegistry2.com/a/b/a/b/package/-/package-1.1.1.tgz

This seems like a strange example, but the use case is myRegistry may be a public facing uri but we would want a way to hit the registries through another uri depending on how the environment is configured (for example if we can not hit the public uri from a protected environment)

Expected Behavior

I would expect replace-registry-host to be able to specify the path that should be replaced instead of just a registry, for example
--replaceRegistryHost=https://myRegistry2.com/a/b/

Steps To Reproduce

The registry can return a tarball that contains a different hostname than the registry
2.

registry=https://myRegistry1.com/a/b
replace-registry-host=always
  1. npm install
  2. Unable to hit the registry (certificate issues)

Environment

  • npm: 8.19.3
  • Node.js: 16.18.0
  • OS Name: MacOS
  • System Model Name: Macbook Pro
  • npm config:
; copy and paste output from `npm config ls` here

Activity

  1. added
    Bugthing that needs fixing
    Needs Triageneeds review for next steps
    Release 8.xwork is associated with a specific npm 8 release
    on Jan 31, 2023
  2. u2mejc commented on Jun 26, 2026

    @u2mejc
    Contributor

    This issue (feature request) is still persistent today. Most third party caches append a URL path prefix for their registry setting and you'll still get errors switching, since the paths at concatenated presently if you use replace-registry-host=always or the bare hostname.

    ie:

    npm error code E404
    npm error 404 Not Found - GET https://new-repo.example.com/api/b/repository/a/my-package/-/my-package-4.0.4.tgz
    

    The PR above resolves this by parsing for paths too. Moving to a new cache looks like this:

    -registry=https://old-repo.example.com/repository/a/
    +registry=https://new-repo.example.com/api/b/
    +replace-registry-host=https://old-repo.example.com/repository/a/

    This allows you to use npm ci without needing to manually edit or delete the lock file, ensuring unpinned module versions don't change simple due to switching caches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions