EckherInsightsToolsContact
Eckher
Your guide to what's next.
Eckher
English
Home › Eckher Insights › Publishing an npm package to GitHub Packages
Feb 25, 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.

Cover
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?
Server-side rendering with code splitting
How to implement server-side rendering with code splitting?
Creating a JavaScript library with webpack
How to bundle a JavaScript library with webpack?
Iterating over Map in JavaScript
Gotchas with iterating over a Map object in JavaScript.
Asynchronous iteration in JavaScript
Gotchas with asynchronous iteration in JavaScript.
Creating a playlist in React
How to create a playlist in React?
Eckher
Your guide to what's next.
Copyright © 2021 Eckher. Various trademarks held by their respective owners.