Search code examples
nexus3

If I have the same package name in Nexus private repo as it is in the npm publish repo, which one takes priority when I install?


I am setting up nexus npm repository, and created npm-group = npm-private+npm-registry (proxy to npm offical registry).

It comes to me thinking that if I publish my own package and name it say "jest" to my private repo, what happens if I do npm install jest? Does it take the private fake one or the one published in official site?

Thanks


Solution

  • You need to use scopes for your private packages. You prefix them with @yournamespace (for instance: "name": "@yournamespace/jest"), and you adjust your npmrc accordingly:

    ; Set a new registry for a scoped package
    @yournamespace:registry=https://mycustomregistry.example.org
    

    Using this scheme, you could use separate npm repositories, one for the proxy to the official npmjs repo, and one for your private packages.

    Otherwise, if you override a package name, it will shadow the one that is proxified, so you will fetch your private package instead of the official one.