Eckher
EckherInsightsContact
Eckher
Your guide to what's next.
Publishing an npm package to GitHub Packages
Mar 9, 2020

Publishing an npm package to GitHub Packages

How to publish an npm package to GitHub Packages?

The GitHub package registry requires authentication for publishing with npm. Generate an access token and add this line to .npmrc:

//npm.pkg.github.com/:_authToken=TOKEN

You can either use ~/.npmrc or create an .npmrc file in you project's root.

The module name specified in the package.json file needs to have a scope. You can only publish packages with the scope matching your GitHub username or organization. For instance, the octocat Github user can only publish @octocat/xxx packages. If the octocat user is a member of the octo-org GitHub organization, they can publish @octo-org/xxx packages.

GitHub Packages are scoped to repositories. Each GitHub repository can have multiple packages. The package is published to the GitHub repository specified in the repository.url field of the package.json file.

See also
npm exec: A new way to run commands from npm packages
npm v7 has introduced the new npm exec command which, like npx, can be used to run npm scripts "on the fly".
Authenticating to an npm registry
How to authenticate to an npm registry?
Loading npm dependencies from multiple registries
How to add npm dependencies from multiple package registries?
Creating a JavaScript library with webpack
How to bundle a JavaScript library with webpack?