Skip to content

Instantly share code, notes, and snippets.

@robwierzbowski
Last active July 19, 2025 09:42
Show Gist options
  • Save robwierzbowski/9fdf661341ec99c3ea0f480f99ac2ea5 to your computer and use it in GitHub Desktop.
Save robwierzbowski/9fdf661341ec99c3ea0f480f99ac2ea5 to your computer and use it in GitHub Desktop.
Configure yarn to use the npm registry directly
#!/bin/bash
# Remove all settings in the .npmrc except the required auth token setting.
echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc
# Create a new .yarnrc that specifies the npm registry, or append to an existing one.
echo 'registry: https://registry.npmjs.org/' >> .yarnrc
# Remove and regenerate the yarn.lock. This should be identical to running `yarn upgrade`.
# If you are uncomfortable regenerating the yarn.lock file, you can comment out the next
# two lines and try manually finding and replacing 'https://registry.yarnpkg.com/' with
# 'https://registry.npmjs.org/'
rm yarn.lock
yarn
# You can check that the registry has been set correctly by running `yarn config list`.
@dimaslanjaka
Copy link

dimaslanjaka commented Jul 19, 2025

To configure Yarn Berry to use a custom NPM registry and enable authentication for the npm scope, use the following commands:

  1. Set the NPM registry server for the npm scope:

    yarn config set npmScopes.npm.npmRegistryServer "https://registry.npmjs.org"
  2. Always authenticate for the npm scope:

    yarn config set npmScopes.npm.npmAlwaysAuth true
  3. Set the authentication token for the npm scope:

    yarn config set npmScopes.npm.npmAuthToken "YOUR_NPM_TOKEN"

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