question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure npm registry via .npmrc

See original GitHub issue

Affected Packages

pkg:@changesets/cli

Problem

Looks like we can only get the npm registry from packageJson.publishConfig or process.env.npm_config_registry when running npm info. Is there a way to get npm registry from .npmrc file?

Screen Shot 2021-09-28 at 9 06 29 PM

Also, is npm_config_registry safe to rely on? Because it’s not documented.

Proposed solution

Read npm registry in the following priorities:

  1. packages/my-package/packageJson.publishConfig
  2. packages/my-package/.npmrc
  3. root/.npmrc

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Nov 20, 2021

Mostly a note for me: I’ve done a quick test and it seems that npm info doesn’t respect packageJson.publishConfig.registry - which makes this very inconvenient for us because we can’t simply rely on calling npm info either way. Maybe we can use --registry only when packageJson.publishConfig.registry is defined and delegate figuring out the correct registry to npm in all other cases.

Probably the easiest way to fix this would be to update the code that looks up the correct registry to pass to the --registry flag to check for 4 places

My current thinking is that we should just avoid using --registry as much as possible and I will experiment with that. When done right it feels like it really should yield the best results without us reimplementing a whole bunch of stuff that is a little bit tricky to get 100% right from the start

npm won’t use the NPM_TOKEN environment variable, since that is for the default registry

Do you simply refer to the NPM_TOKEN used by our GitHub action since we only set it up in .npmrc for the default registry or are you referring to a broader standard? in other words - Is NPM_TOKEN used by npm itself anyhow?

@hayes thank you once again for the detailed write up about this issue. This has helped me to understand the complexity involved here much better. I’m currently working on improving the compatibility with publishing using pnpm and yarn - when I land this work I will be looking into fixing this one as it’s a very important feature that is not working correctly right now. I have very limited time resources though - so it won’t happen over night, please bear with me 😉

0reactions
hayescommented, Oct 11, 2021

I have no idea how to use this. When this gets picked up over registry?

I think this should get used any time you install OR publish a package from that scope

What you wrote above looks like it matches my understanding

Read more comments on GitHub >

github_iconTop Results From Across the Web

registry | npm Docs
npm is configured to use the npm public registry at https://registry.npmjs.org by default. Use of the npm public registry is subject to terms...
Read more >
Configure Your NPM Registry Settings - Nono Martínez Alonso
Run the npm config list command to see what variables are set. If you run this in a project folder with an .npmrc...
Read more >
using myproject/.npmrc with registry - Stack Overflow
UPDATE: It is possible to work around the problem (npm is tied to only one registry). First you have to add a scope...
Read more >
Working with the npm registry - GitHub Docs
You can use an .npmrc file to configure the scope mapping for your project. In the .npmrc file, use the GitHub Packages URL...
Read more >
Configuring Your .npmrc for an Optimal Node.js Environment
Or, you may be using Certified Modules as a custom npm registry. There's even a separate registry for Yarn, a topic that is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found