How to add npm dependencies from multiple package registries?
package.json
It is possible that the project uses dependencies from the npm registry and one or more GitHub Packages.
By default, npm install
loads the modules from the npm package registry, https://registry.npmjs.org/, because this is the default value of registry
in the npm config (a line in .npmrc
or npm config get registry
):
registry=https://registry.npmjs.org/
If this value is changed to say, https://npm.pkg.github.com
, npm install
will try to load all project dependencies from GitHub Packages. It is possible, however, to override this value for a specific @SCOPE using the following syntax:
@SCOPE:registry=https://npm.pkg.github.com/
For instance, if the project has the following package.json
:
{
"dependencies": {
"@octo-org/octo-app": "1.0.0",
"react": "^16.9.0"
}
}
and .npmrc
:
@octo-org:registry=https://npm.pkg.github.com/
then npm install
will download react
from the npm registry and @octo-org/octo-app
from GitHub Packages.
This configuration allows one registry to host multiple scopes, but a scope can only point to a single registry.
Thanks for stopping by my digital playground! If you want to say hi, you can reach out to me on LinkedIn or via email. I'm always keen to chat and connect.
If you really-really like my work, you can support me by buying me a coffee.