Diese Version von GitHub Enterprise wurde eingestellt am 2021-09-23. Es wird keine Patch-Freigabe vorgenommen, auch nicht für kritische Sicherheitsprobleme. Für eine bessere Leistung, verbesserte Sicherheit und neue Features nimm ein Upgrade auf die neueste Version von GitHub Enterprise vor. Wende Dich an den GitHub Enterprise-Support, um Hilfe beim Upgrade zu erhalten.

Working with the npm registry

Sie können NPM für die Veröffentlichung von Paketen auf GitHub Packages und für die Nutzung von auf GitHub Packages gespeicherten Paketen als Abhängigkeiten in einem NPM-Projekt konfigurieren.

GitHub Packages is available with GitHub Free, GitHub Pro, GitHub Free for organizations, GitHub Team, GitHub Enterprise Cloud, GitHub Enterprise Server, and GitHub AE.

Note: GitHub Packages is currently in beta for GitHub Enterprise Server 2.22. To join the beta for your GitHub Enterprise Server instance, use the sign-up form.

Note: When installing or publishing a docker image, GitHub Packages does not currently support foreign layers, such as Windows images.

Bei GitHub Packages authentifizieren

You need an access token to publish, install, and delete packages.

You can use a personal access token (PAT) to authenticate to GitHub Packages or the GitHub API. When you create a personal access token, you can assign the token different scopes depending on your needs. For more information about packages-related scopes for a PAT, see "About permissions for GitHub Packages."

To authenticate to a GitHub Packages registry within a GitHub Actions workflow, you can use:

  • GITHUB_TOKEN to publish packages associated with the workflow repository.
  • a PAT to install packages associated with other private repositories (which GITHUB_TOKEN can't access).

For more information about GITHUB_TOKEN used in GitHub Actions workflows, see "Authentication in a workflow."

Authenticating with a personal access token

Du musst ein persönliches Zugriffstoken mit dem entsprechenden Geltungsbereich verwenden, um Pakete in GitHub Packages zu veröffentlichen und zu installieren. Weitere Informationen findest Du unter „Über GitHub Packages."

You can authenticate to GitHub Packages with npm by either editing your per-user ~/.npmrc file to include your personal access token or by logging in to npm on the command line using your username and personal access token.

To authenticate by adding your personal access token to your ~/.npmrc file, edit the ~/.npmrc file for your project to include the following line, replacing HOSTNAME with the host name of your GitHub Enterprise Server instance and TOKEN with your personal access token. Create a new ~/.npmrc file if one doesn't exist.

If your instance has subdomain isolation enabled:

//npm.HOSTNAME//:_authToken=TOKEN

If your instance has subdomain isolation disabled:

$ npm login --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS

To authenticate by logging in to npm, use the npm login command, replacing USERNAME with your GitHub username, TOKEN with your personal access token, and PUBLIC-EMAIL-ADDRESS with your email address.

If GitHub Packages is not your default package registry for using npm and you want to use the npm audit command, we recommend you use the --scope flag with the owner of the package when you authenticate to GitHub Packages.

If your instance has subdomain isolation enabled:

$ npm login --scope=@OWNER --registry=https://npm.HOSTNAME/

> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS

If your instance has subdomain isolation disabled:

$ npm login --scope=@OWNER --registry=https://HOSTNAME/_registry/npm/
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS

Ein Paket veröffentlichen

Note: Package names and scopes must only use lowercase letters.

By default, GitHub Packages publishes a package in the GitHub repository you specify in the name field of the package.json file. Ein Paket namens @my-org/test würde beispielsweise im Repository my-org/test auf GitHub veröffentlicht. You can add a summary for the package listing page by including a README.md file in your package directory. For more information, see "Working with package.json" and "How to create Node.js Modules" in the npm documentation.

You can publish multiple packages to the same GitHub repository by including a URL field in the package.json file. For more information, see "Publishing multiple packages to the same repository."

Die Scope-Zuordnung für Ihr Projekt können Sie entweder über die lokale .npmrc-Datei im Projekt oder die Option publishConfig in der Datei package.json festlegen. GitHub Packages only supports scoped npm packages. Pakete mit Scopes weisen Namen im Format @owner/name auf. Pakete mit Scopes beginnen immer mit dem Symbol @. You may need to update the name in your package.json to use the scoped name. Beispiel: "name": "@codertocat/hello-world-npm".

Nachdem Du ein Paket veröffentlicht hast, kannst Du das Paket auf GitHub ansehen. Weitere Informationen findest Du unter „Anzeigen von Paketen."

Publishing a package using a local .npmrc file

You can use an .npmrc file to configure the scope mapping for your project. In the .npmrc file, use the GitHub Packages URL and account owner so GitHub Packages knows where to route package requests. Using an .npmrc file prevents other developers from accidentally publishing the package to npmjs.org instead of GitHub Packages.

  1. Authentifizieren bei GitHub Packages. Weitere Informationen findest Du unter „Bei GitHub Packages authentifizieren“.

  2. Erstelle oder bearbeite eine .npmrc Datei im gleichen Verzeichnis wie Deine package.json Datei, um eine Zeile mit der GitHub Packages-URL und dem Kontoinhaber einzufügen. Ersetze OWNER durch den Namen des Benutzer- oder Organisationskonto, welches das Repository besitzt, in dem sich Dein Projekt befindet.

    If subdomain isolation is enabled:

    @OWNER:registry=https://npm.HOSTNAME

    If subdomain isolation is disabled:

    @OWNER:registry=https://HOSTNAME/_registry/npm
  3. Füge die .npmrc Datei in das Repository hinzu, wo GitHub Packages Dein Projekt finden kann. Weitere Informationen findest Du unter „Eine Datei zu einem Repository hinzufügen.“

  4. Überprüfen Sie den Namen Ihres Pakets in der Datei package.json Ihres Projekts. Das Feld name (Name) muss den Scope und den Namen des Pakets enthalten. Wenn z. B. Ihr Paket „test“ heißt und Sie es in der GitHub-Organisation „My-org“ veröffentlichen möchten, muss das Feld name (Name) in der Datei package.json @my-org/test enthalten.

  5. Überprüfe das repository Feld in der Datei package.json Deines Projekts. Das repository Feld muss mit der URL für Dein GitHub Repository übereinstimmen. Wenn Deine Repository-URL beispielsweise github.com/my-org/test ist, sollte das Repository-Feld git://github.com/my-org/test.git sein.

  6. Das Paket veröffentlichen:

    $ npm publish

Publishing a package using publishConfig in the package.json file

You can use publishConfig element in the package.json file to specify the registry where you want the package published. Weitere Informationen finden Sie unter „publishConfig“ in der NPM-Dokumentation.

  1. Bearbeiten Sie die Datei package.json für Ihr Paket, und fügen Sie den Eintrag publishConfig hinzu.

    If your instance has subdomain isolation enabled:

    "publishConfig": {
      "registry":"https://npm.HOSTNAME/"
    },

    If your instance has subdomain isolation disabled:

    "publishConfig": {
       "registry":"https://HOSTNAME/_registry/npm/"
     },
  2. Überprüfe das repository Feld in der Datei package.json Deines Projekts. Das repository Feld muss mit der URL für Dein GitHub Repository übereinstimmen. Wenn Deine Repository-URL beispielsweise github.com/my-org/test ist, sollte das Repository-Feld git://github.com/my-org/test.git sein.

  3. Das Paket veröffentlichen:

    $ npm publish

Publishing multiple packages to the same repository

To publish multiple packages to the same repository, you can include the URL of the GitHub repository in the repository field of the package.json file for each package.

To ensure the repository's URL is correct, replace REPOSITORY with the name of the repository containing the package you want to publish, and OWNER with the name of the user or organization account on GitHub that owns the repository.

GitHub Packages will match the repository based on the URL, instead of based on the package name.

"repository":"https://HOSTNAME/OWNER/REPOSITORY",

Ein Paket installieren

You can install packages from GitHub Packages by adding the packages as dependencies in the package.json file for your project. For more information on using a package.json in your project, see "Working with package.json" in the npm documentation.

By default, you can add packages from one organization. For more information, see "Installing packages from other organizations."

You also need to add the .npmrc file to your project so that all requests to install packages will go through GitHub Packages. When you route all package requests through GitHub Packages, you can use both scoped and unscoped packages from npmjs.org. For more information, see "npm-scope" in the npm documentation.

  1. Authentifizieren bei GitHub Packages. Weitere Informationen findest Du unter „Bei GitHub Packages authentifizieren“.

  2. Erstelle oder bearbeite eine .npmrc Datei im gleichen Verzeichnis wie Deine package.json Datei, um eine Zeile mit der GitHub Packages-URL und dem Kontoinhaber einzufügen. Ersetze OWNER durch den Namen des Benutzer- oder Organisationskonto, welches das Repository besitzt, in dem sich Dein Projekt befindet.

    If subdomain isolation is enabled:

    @OWNER:registry=https://npm.HOSTNAME

    If subdomain isolation is disabled:

    @OWNER:registry=https://HOSTNAME/_registry/npm
  3. Füge die .npmrc Datei in das Repository hinzu, wo GitHub Packages Dein Projekt finden kann. Weitere Informationen findest Du unter „Eine Datei zu einem Repository hinzufügen.“

  4. Configure package.json in your project to use the package you are installing. To add your package dependencies to the package.json file for GitHub Packages, specify the full-scoped package name, such as @my-org/server. For packages from npmjs.com, specify the full name, such as @babel/core or @lodash. For example, this following package.json uses the @octo-org/octo-app package as a dependency.

    {
      "name": "@my-org/server",
      "version": "1.0.0",
      "description": "Server app that uses the @octo-org/octo-app package",
      "main": "index.js",
      "author": "",
      "license": "MIT",
      "dependencies": {
        "@octo-org/octo-app": "1.0.0"
      }
    }
    
  5. Installieren Sie das Paket.

    $ npm install

Pakete von anderen Organisationen installieren

Standardmäßig können Sie nur GitHub Packages-Pakete von einer Organisation verwenden. If you'd like to route package requests to multiple organizations and users, you can add additional lines to your .npmrc file, replacing HOSTNAME with the host name of your GitHub Enterprise Server instance and OWNER with the name of the user or organization account that owns the repository containing your project.

If your instance has subdomain isolation enabled:

@OWNER:registry=https://npm.HOSTNAME
@OWNER:registry=https://npm.HOSTNAME

If your instance has subdomain isolation disabled:

@OWNER:registry=https://HOSTNAME/_registry/npm
@OWNER:registry=https://HOSTNAME/_registry/npm

Weiterführende Informationen