2

I'm not sure how to install (npx) a package from github registry when that package is depending on one or multiple packages from the public npm registry.

I tried:

npm_config_registry=https://npm.pkg.github.com npx @octopol/development

But it fails because some of the dependencies are located on the public npm registry:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/@era-ci%2futils - npm package "utils" does not exist under owner "era-ci"
npm ERR! 404
npm ERR! 404  '@era-ci/utils@^2.0.27' is not in this registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

I'm not sure how all github-npm-registry customers are using this registry. What am I missing here?

Stav Alfi
  • 13,139
  • 23
  • 99
  • 171
  • If your using none NPM repository's, you need to scope them -> https://github.com/features/packages – Keith Nov 09 '21 at 10:55
  • Thanks but I already have scopes on my package (`@octopol/development`). What are you trying to suggest? – Stav Alfi Nov 09 '21 at 11:36
  • I've never used GitHub's npm, but a scope is `@octopol` not `@octopol/development`, and then your meant to `npm login --registry=someregistry --scope=@somescope` And then when you do -> `npm install @somescope/somepackage`.. IOW: A scope determines what registry to use, your `development` bit is the package inside this scope. – Keith Nov 09 '21 at 11:43
  • When you do `npm install @somescope/somepackage`, you need to specify registry because it is not in the public npm registry. – Stav Alfi Nov 09 '21 at 12:02
  • No, `@somescope` could well be also in the public npm registry, eg. `@types` Microsofts typescript types are in the NPM registry,.. It's just that `@scopes` can be used to dictate what registry to use. Like I mentioned I don't use GitHub's npm, but I do use my own private NPM server, and if I so desired I could even scope `@types` to point at my private NPM server, wouldn't be a good idea like. So I of course make sure the scope name I use does not clash with NPM's.. – Keith Nov 09 '21 at 12:26
  • this scope is not on npm. how do you suggest to solve my problem? – Stav Alfi Nov 09 '21 at 13:16
  • It doesn't need to be on NPM, as I mentioned in my previous comment. You decide what to name the scopes if there not hosted on NPM. To be honest, not sure what problem I need to solve. It's pretty simple, you need to `npm login` using your github account, and associate that with some scope,.. You could call in `@my_xyz_scope_thats_not_in_npm` it's up to you. – Keith Nov 09 '21 at 13:19

1 Answers1

1

with the one liner you are overwriting the registry for all packages. instead you need to define the github registry for that particular package only

I would suggest you create an .npmrc file with

registry=https://registry.npmjs.org/

@octopol:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=<your auth token>
always-auth=true

Get your token from https://github.com/settings/tokens

this is the documentation: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#installing-a-package

also without token you should be hitting an authentication issue as per https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages#authenticating-to-github-packages

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

code credit: https://gist.github.com/ThallyssonKlein/8d24eb20c101c1f20036cee77e24524c

upepo
  • 11
  • 2