I signed up for the Github private npm registry beta and followed their instruction: https://github.com/features/package-registry
Works great with npm but I'd prefer using yarn. And while npm has no issues finding the registered package, yarn can't find it at all.
yarn add @omniphx/adminite-adminite-ui-components
outputs:
yarn add v1.19.0 info No lockfile found. warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json. [1/4] 🔍 Resolving packages... error Couldn't find package "@omniphx/adminite-ui-components" on the "npm" registry. info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
After reading up on private repos with yarn, I thought the trick was due to yarn having a slightly different rc format. Unfortunately, that didn't work either and yarn is still unable to find the private registry.
.npmrc
registry=https://registry.npmjs.org @omniphx:registry=https://npm.pkg.github.com/omniphx
.yarnrc
registry "https://registry.npmjs.org" "@omniphx:registry" "https://npm.pkg.github.com/omniphx"
Also confirmed that my github token is set too with yarn config list
:
yarn config v1.19.0 info yarn config { 'version-tag-prefix': 'v', 'version-git-tag': true, 'version-commit-hooks': true, 'version-git-sign': false, 'version-git-message': 'v%s', 'init-version': '1.0.0', 'init-license': 'MIT', 'save-prefix': '^', 'bin-links': true, 'ignore-scripts': false, 'ignore-optional': false, registry: 'https://registry.npmjs.org', 'strict-ssl': true, 'user-agent': 'yarn/1.19.0 npm/? node/v12.11.1 darwin x64', email: '[email protected]', lastUpdateCheck: 1570679687836, username: 'omniphx', '@omniphx:registry': 'https://npm.pkg.github.com/omniphx' } info npm config { '//npm.pkg.github.com/:_authToken': 'fake12345', registry: 'https://registry.npmjs.org', '@omniphx:registry': 'https://npm.pkg.github.com/omniphx', python: '/usr/bin/python' }
Any idea?
Resolved
Changed "@myorg:registry" "https://npm.pkg.github.com/myorg" To "@myorg:registry" "https://npm.pkg.github.com"
Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node.
A private repository will be published as a private npm package. Perhaps the first step in making your package private is to make your package's repository private. To make your Github repository private, click on the Settings tab, scroll to the bottom and then click on Change repository visibility.
I've just run into a similar situation. It seemed that yarn
was only looking in the main Yarn package registry for my organization's private package. I had copied the examples from GitHub's Packages documentation for constructing your .npmrc
file directly to the .yarnrc
file in the project that will be consuming the app, not knowing that the formats were different (I've never had to deal with .yarnrc
files before).
However, after updating the .yarnrc
file with the correct format that you've mentioned above (which I also found in googling around), yarn
successfully found the private package and installed it correctly.
As a heads up, my yarn
version: 1.17.3
cd
to the projectnvm use
(if you have a specific node version to use).yarnrc
file to the project. See below for what it looks like. package.json
for my private packagenpm login --registry=https://npm.pkg.github.com --scope=@MyOrg
yarn
That worked for me.
"@myorg:registry" "https://npm.pkg.github.com"
Note: See below for a note on the org / scope name gotcha's
I know that it appears that you don't have any issues with this, given your GH username / scope above, but for anyone else that comes here, the documentation on GH is a little sparse with regards to mapping your username / org name to a scope in the package name. Just remember these little gotcha's here:
name: @johndturn/my-package
MyOrg
, just replace them in the name of the package in your package.json
and your .yarnrc
with lowercase name: @myorg/my-package
npm login
, I still have kept the uppercase letters in the --scope=
argument. MyOrg/random-prefix.js-lib
, you can have name: @myorg/js-lib
in your package.json
file for the project itself. Then, installing it in other projects will look something like @myorg/js-lib: 1.0.0
. The problem I had is slightly different.
After tried what John suggested I still can't add private registry packages with yarn
(but perfectly fine with npm
)
Then I realise two things:
For GitHub packages, npm
is fine with either
registry=https://npm.pkg.github.com/my-org
or
@my-org:registry=https://npm.pkg.github.com
but yarn
only allow the latter syntax.
Docs from Github website only show the first syntax which could cause problems for yarn users.
Another thing is that if you npm login
to the private registry but use a .yarnrc
file in your project, yarn can't really mix your npm
credentials with it. Although it seems behave differently on different environment.
But it would seems to be a best practice to stick with either yarn login
+ .yarnrc
, or npm login
+ .npmrc
(you can still use yarn to manage your packages in both cases)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With