What is the process of utilizing multiple npm registries within Yarn?

Currently, I am facing a challenge while setting up Yarn 0.17.9 in our environment due to issues with our registry setup. Our environment involves two registries - the official npmjs registry and our own internal network registry (Sinopia).

The main issue arises when we try to pull packages from either registry using the --registry flag in npm install. However, the problem occurs because the yarn add command does not have a --registry option, making it difficult to set a custom registry globally with fallback to npmjs. I attempted to use the .npmrc file but it only allows one registry for npm/yarn within a project. Additionally, the .yarnrc file does not seem to be effective and is overridden by the .npmrc.

Is there a way to specify two registries, with a fallback to the second registry if the package is not found in the first one? Alternatively, is there a method to define a different npm registry for each individual package?

Answer №1

Creating a .yarnrc file at the project's root directory allows you to specify a custom repository by adding this line:

registry "https://registry.npmjs.org/"

Using this method will establish a project-specific repository for your project.

Answer №2

For anyone stumbling upon this in the year 2021, it's worth noting that yarn has now made advancements in its functionality. It can now handle scopes, private registries, and authentication.

As an illustration, I have successfully published private packages such as

@my-company-private-scope/my-package
to a Verdaccio (which is essentially a fork of Sinopia) server. My configuration in the .npmrc file looks like this:

; Any lines starting with ; are meant for .npmrc file comments
; With yarn 1.22.10, it seems that the default registry is set to https://registry.yarnpkg.com
; regardless of what is specified here
; registry=https://registry.npmjs.com/

@my-company-private-scope:registry=https://npm.my-company.com/
//npm.my-company.com/:_authToken=TOKEN

; Surprisingly, I didn't feel the necessity to include this, as
; yarn was still able to successfully install both public and private packages
; based on the contents of my yarn.lock file
; //npm.my-company.com/:always-auth true

It appears that npm also provides support for scopes. While yarn unpublish may not be available, I found that

npm unpublish @my-company-private-scope/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a5c8dc88d5c4c6cec4c2c0e5948b958b948890">[email protected]</a>
worked seamlessly.

Although I haven't yet had the need to experiment with multiple scopes across various private servers (though I might consider it in the future, perhaps), there doesn't seem to be any glaring reasons why it wouldn't function just as smoothly.

Answer №3

While Yarn lacks a built-in --registry flag like npm, you have the option to define your registry in the .yarnrc file.

If your .yarnrc settings are not taking effect, you can manually set the registry by copying it from the ~/.yarnrc file using:

yarn config set registry http://custom.registry.com/

Answer №4

If you're facing issues, consider changing the registry settings in your .npmrc and .yarnrc files.

For instance, in your .npmrc:

registry=https://yourcompany/
virtual/:_authToken=credentials
always-auth=true

It's crucial that always-auth=true is placed as the last line in the file.

And within your .yarnrc:

registry "https://registry.yarnpkg.com"

By making these adjustments, commands like yarn add or npm install should now support both private and public packages.

Answer №5

In the latest version 3 (3.4.1) of the software, it is now possible to set up multiple repositories by configuring the .yarnrc.yml file, for example including GitHub Packages:

npmScopes: 
  your-organization-or-account:
    npmRegistryServer: "https://npm.pkg.github.com"

To explore additional options, refer to the Yarn documentation under 'npmScopes': yarn-docs

Note that this configuration method remains consistent in version 4 (currently at 4.0.2).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to transmit JavaScript information to my NodeJS server

Having some trouble sending geolocation data to NodeJS through a POST request. When I check the console log in my NodeJS code, it's just showing an empty object. I've already tested it with postman and had no issues receiving the data. The probl ...

Utilizing AngularJS to filter prices within a specific range using a button

I am new to using angularjs and I am working on implementing a price range filter with nouislider for a list of products with different prices. I want the filtering to happen only after the user clicks on the filter button. Below is the HTML code for my " ...

Handlebars: The property "from" cannot be accessed because it is not an "own property" of its parent and permission has been denied

My backend is built on Node.js and I am using server-side rendering with handlebars. I have a `doc` array of objects in handlebars that contains keys "content" and "from". However, when I try to loop through this array using `#each`, I encounter the error ...

What is the best way to ensure all my borders are uniform in size?

As I work on a JavaScript project that organizes words into blocks based on their size, I encountered an issue with inconsistent border thickness in certain areas. I'm using spans to contain each word, but I can't figure out how to make the borde ...

What is the best way to update a CSS class in React JS?

Suppose I have a CSS class called 'track-your-order' in my stylesheet. Whenever a specific event occurs, I need to modify the properties of this class and apply the updated values to the same div without toggling it. The goal is to replace the ex ...

Is it advisable for postcss plugins to list postcss as a peer dependency?

I'm trying to incorporate the PostCSS Sass Color Function into my project. Unfortunately, I encountered this error: PostCSS plugin error: Your current version of PostCSS is 6.0.22, while postcss-sass-color-functions requires 5.2.18. This discrepa ...

Steps for assigning a texture to a child Mesh within an Object3D

My Object3D was imported in the following manner: var customObject; // defining a global object var loader = new THREE.ObjectLoader(); loader.load('path/to/object3d.json', function(object) { customObject = object; scene.add(customObject ...

VueJS: Send all unspecified attributes to child component in the same way as using v-bind="$props"

I am looking for a way to receive any props passed by the parent component into the child component without explicitly mentioning them in props:[]. This is because I may not always know which props will be bound. Parent component <template> <di ...

Ways to reset input fields following form submission

I've been trying to figure out how to clear the input fields once the form is submitted, but for some reason, the input data remains there even after each submission. I'm using ajax jquery form. Any ideas on how to resolve this issue? Thank you ...

Using CasperJS, learn how to effectively utilize the jQuery find() function

I'm looking to implement something similar to Cabybara within a function in CasperJS. My goal is to select parent divs and extract text from their child elements. Here's an example of what I want: $('div.education').find('h4&apos ...

Problems with Angular functionality

I'm a newbie when it comes to Angular and I'm eager to start practicing some coding. I've put together a simple app, but for some reason, the Angular expression isn't getting evaluated in the browser. When I try to display {{inventory.p ...

Choose an element from within a variable that holds HTML code

I have a specific div element that I need to select and transfer to a new HTML file in order to convert it into a PDF. The issue I'm facing is related to using AJAX in my code, which includes various tabs as part of a management system. Just to prov ...

Serving sourcemaps for a web extension in Firefox: A step-by-step guide

Currently in the process of developing a web extension using TypeScript, I have encountered an issue with sourcemaps not loading properly. The use of parcel to bundle my extension has made the bundling process simple and straightforward. However, while the ...

At what point does the event loop in node.js stop running?

Could you please enlighten me on the circumstances in which the event loop of node.js terminates? How does node.js determine that no more events will be triggered? For instance, how does it handle situations involving an HTTP client or a file reading app ...

Encountering a MODULE_NOT_FOUND error while trying to execute "npm run build"

I have encountered an issue while trying to deploy my application on my GoDaddy server. Upon running 'npm run build,' I am receiving the following error message: PS C:\Users\trump\Documents\Rider Project\PreChiS-E---Stud ...

Creating a dynamic text field integrated with Google Places in Ionic 4: a step-by-step guide

I am currently implementing the google-place-api autoComplete feature in my project, but I encountered an error: TypeError: Cannot read property 'getInputElement' of undefined .html <section [formGroupName]="i" *ngFor="l ...

An issue occurred while attempting to execute the npm start command

While attempting to create a React project, I used npx create-react-app hello-react --use-npm and then navigated to the hello-react directory using cd hello-react. However, when I tried to run npm start, I encountered the following error: npm ERR! code ENO ...

Creating dynamically generated routes in Angular or Angular 9 before initialization

I'm currently working on a project where I am in the process of converting an AngularJS application to Angular. The main challenge that I am facing at the moment revolves around routing. To sum it up: My requirement is to define routes based on an AP ...

Experiencing delays with AngularJS $http responses

I have this code snippet which is causing an issue: $http.get('/api/users'). success(function(data) { $scope.authors = data; }). error(function() { console.log('API error - configuration.') }); Further down in the code: for ( ...

How can I retrieve information on a logged in Auth0 user from an API?

I'm currently working on a React application that utilizes auth0 in conjunction with an express API server. One issue I'm facing is how to access user information within the API when a secure endpoint is called. While I can retrieve user data on ...