How to use Yarn registry as Azure DevOps artifact upstream feed? - azure-devops

I have a mono repo in Azure DevOps that contains JavaScript packages. I use lerna for managing packages and yarn as package manager. I'm new to Azure DevOps artifacts and I want to setup yarn to be a upstream feed. I have read Use npm to store JavaScript packages in Azure DevOps Services or TFS and followed the steps. With npm seems everything works fine and after I enter npm i in my project I can see packages that sourced npm in azure artifact. But if I use yarn nothing happens. Can somebody help me?
Project .npmrc:
registry=https://pkgs.dev.azure.com/<OrganizationName>/_packaging/<OrganizationName>/npm/registry/
always-auth=true
Global .npmrc in %HOMEPATH%\.npmrc
//pkgs.dev.azure.com/<OrganizationName>/_packaging/<OrganizationName>/npm/registry/:_authToken=blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah
I also go to feed settings and add yarn registry as new public upstream source and move it up to be 1st upstream source. but if I enter yarn install in my project and then go to Azure artifacts and filter artifacts by source yarn nothing shown.
npm ping with that .npmrcs:
path\to\project's\package.json>npm ping
npm notice PING https://pkgs.dev.azure.com/<OrganizationName>/_packaging/<OrganizationName>/npm/registry/
npm ERR! code E404
npm ERR! 404 Not Found - GET https://pkgs.dev.azure.com/<OrganizationName>/_packaging/<OrganizationName>/npm/registry/-/ping?write=true
npm ERR! 404
npm ERR! 404 'ping' is not in the npm 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.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\<UserName>\AppData\Roaming\npm-cache\_logs\2020-03-27T03_20_26_797Z-debug.log
npm ping in somewhere else:
C:\WINDOWS\system32>npm ping
npm notice PING https://registry.npmjs.org/
npm notice PONG 1.296ms

I deleted Yarn cache folder in %LOCALAPPDATA%\Yarn\Cacheand also yarn.lock file and node_modules folder in my project root and then reinstalled packages. I think problem was due to yarn.lock file. Because in yarn.lock file for each package specified registry and because I haven't package-lock.json npm works and yarn doesn't.
You can see before I delete yarn.lock file and after I reinstall package in image blow:

Related

Get npm error npm ERR! 404 '#my-package#2.0.0' is not in this registry when try to publish new npm package version to npm

I get below npm error when trying to publish a new version of my package to npm.
The package is 'public' and previously published by someone else.
updated code and merged to master
run npm version major and merged package.json and package-lock.json to master
npm login
npm publish
I get below error:
npm notice Publishing to https://registry.npmjs.org/ npm ERR! code
E404 npm ERR! 404 Not Found - PUT
https://registry.npmjs.org/#my-package - Not found npm ERR! 404 npm
ERR! 404 '#my-package#2.0.0' is not in this registry.
I received a 404 until I provided a repository field in package.json when publishing to Github Packages. Unhelpful error.

JFrog Artifactory publish vs deploy

I have an Artifactory server (service). I set up a local repository there that I am using for hosting Unity packages. I figured out how to setup scoped packages that Unity Package Manager can see. It's all working pretty well. My only issue is with command line deploying of the artifacts. From what I read it looks like I need to use "npm publish" to deploy. When I call npm "publish" on the tarball file (package file) that I have, it doesn't get uploaded (deployed) to the server. I have to manually upload it using the web UI. The command itself doesn't fail - it prints out list of files, version, name, etc. And ends with something like this
<package name>#x.x.x
What is the point of the (npm) publish command if that's not how you upload (deploy) packages? What is the proper way to upload packages to Artifactory without using the web interface?
Btw, I started with this tutorial: Medium Article. I get similar output when i run publish command locally, so it seems like that should be uploading the package for me, but it doesn't. Another note: i do use scoped packages - i used all of the instructions that Artifactory and that tutorial provides. I get no errors anywhere. Just nothing happens when i publish.
Any suggestions?
Edit:
This is the command I run:
npm publish <packagename>.x.x.x.tgz --registry http://<server>artifactory/api/npm/unity_packages/<scope>
I saw this thread thread, but I would rather not use curl (i have to replicate this setup on various machines, so less moving parts is better for me) and it is also super old, so i figured there is a newer / better way to deploy.
Edit2: I can also "npm install" packages that I deployed using the web UI, so I do't think it's a permission issue.
Edit3: Sample output:
npm publish --registry http://artifactory.ops.aws.somecompany.net/artifactory/api/npm/unity_packages/
npm notice
npm notice 📦 #com.somecompany/com.somecompany.dependencypackageproject#0.1.207
npm notice === Tarball Contents ===
npm notice 388B DependencyPackageProject.asmdef
npm notice 611B Source/Floater.cs
npm notice 1.1kB package_internal.json
npm notice 1.1kB package.json
npm notice 2.1kB Material/FloaterMaterial.mat
npm notice 166B DependencyPackageProject.asmdef.meta
npm notice 155B Scenes/DPP_SampleScene.unity.meta
npm notice 243B Source/Floater.cs.meta
npm notice 182B Material/FloaterMaterial.mat.meta
npm notice 154B Prefabs/FloaterPrefab.prefab.meta
npm notice 172B Material.meta
npm notice 158B package_internal.json.meta
npm notice 158B package.json.meta
npm notice 172B Prefabs.meta
npm notice 172B Scenes.meta
npm notice 172B Source.meta
npm notice 4.0kB Prefabs/FloaterPrefab.prefab
npm notice 10.3kB Scenes/DPP_SampleScene.unity
npm notice === Tarball Details ===
npm notice name: #com.somecompany/com.somecompany.dependencypackageproject
npm notice version: 0.1.207
npm notice package size: 5.5 kB
npm notice unpacked size: 21.4 kB
npm notice shasum: 77188f8f599877d7a6a41bbcb1800057a3fe1646
npm notice integrity: sha512-vbtkwkiEacQl/[...]dPb8xlhO36odg==
npm notice total files: 18
npm notice
+ #com.somecompany/com.somecompany.dependencypackageproject#0.1.207
In order to publish a scoped npm package to Artifactory using the npm client you need to:
(1) Make sure your package is created as a scoped package as described in the npm documentation
(2) Associate the relevant Artifactory npm repository (for example npm-local) with the scope you are using, by updating your .npmrc configuration file. The file should also contain the authentication information.You can follow the instructions in the Artifactory documentation. Your .npmrc file should look similar to the following:
#drorb:registry=http://localhost:8081/artifactory/api/npm/npm-local/
//localhost:8081/artifactory/api/npm/npm-local/:_password=*********
//localhost:8081/artifactory/api/npm/npm-local/:username=drorb
//localhost:8081/artifactory/api/npm/npm-local/:email=*****#gmail.com
//localhost:8081/artifactory/api/npm/npm-local/:always-auth=true
(3) Use the npm publish command, for example
npm publish craftyjs-npm-example-1.0.0.tgz --registry http://localhost:8081/artifactory/api/npm/npm-local/
Output of the publish command should be similar to
npm notice
npm notice 📦 #drorb/craftyjs-npm-example#1.0.0
npm notice === Tarball Contents ===
npm notice 662B package.json
npm notice 587B .npmignore
npm notice 116B README.md
npm notice 195B game.js
npm notice === Tarball Details ===
npm notice name: #drorb/craftyjs-npm-example
npm notice version: 1.0.0
npm notice package size: 1.6 kB
npm notice unpacked size: 1.6 kB
npm notice shasum: 8ee8bdbfac6ae92fcdcdc7441793671ce59a3584
npm notice integrity: sha512-4DA3LCwO+vuCo[...]FYPGTtxOrg6UQ==
npm notice total files: 4
npm notice

NPM Install from GH Packages: works locally but not in GH action

I have published a private package to our org's package repository.
As per the documentation I added an .npmrc file to another project's root with the following content:
registry=https://npm.pkg.github.com/my-org
In my local ~/.npmrc the sits my Authtoken for npm.pkg.github.com
I installed the published package in my package.json with the following entry in the package.json
"#my-org/my-package": "^1.0.0",
When installing locally this works fine.
When installing via Github Actions the installation fails with the following error:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/my-org/#my-org%2fmy-package - npm package "my-package" does not exist under owner "my-org"
npm ERR! 404
npm ERR! 404 '#my-org/my-package#1.0.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
It seems like "my-org" is used two times in the path to the package?
Why does it work locally but not in Github Actions?
Originally my .npmrc only was like this (no org added to the registry URL):
registry=https://npm.pkg.github.com
That also works fine locally.
It also works for all scoped packages (like #coogle-cloud) in the github Action but did not work for unscoped packages:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://npm.pkg.github.com/chai
npm ERR! 404
npm ERR! 404 'chai#4.2.0' is not in the npm 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.
Update:
so, I took my personal accesstoken (which worked locally) and commited, now the install workflow suceeds.
The documentation (https://help.github.com/en/github/managing-packages-with-github-packages/using-github-packages-with-github-actions) says: "the GITHUB_TOKEN has read:packages and write:packages scopes."
Isn't that sufficient? 
My personal access token has delete:packages, read:packages, repo, write:packages.
buried in some arbitrary twitter thread is the information that the GITHUB_TOKEN only has access to the current repo.
https://twitter.com/char_fish/status/1191442780729556993?s=21
The solution is to explicitly define a personal (sic!) access token and to place in the secrets store of the repository using this secret to authenticate against the package repository.
- name: 'authenticate with GH package registry'
run: echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

400 error when running npm install related to GitHub

I use two Github platform. The public one at https://github.com and my work enterprise one https://github.work.com.
I haven't had any trouble before but I'm trying to run npm install. The project has a package.json file which contains a dependency which is references a repository in my work in git:
"my-dependency-sdk": "git+https://git#github.work.com:organization/my-dependency-sdk.git"
This is the output from the install:
npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://git#github.work.com/:organization/my-dependency-sdk.git
npm ERR!
npm ERR! fatal: unable to access 'https://git#github.work.com/:organization/my-dependency-sdk.git/': The requested URL returned error: 400
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/me/.npm/_logs/2018-04-10T17_44_59_498Z-debug.log
Is it possible that the Git installation on my Mac holds some configuration that may be pointing to the public Github and the repository I'm looking for isn't there?
The URL was incorrect. It should have been:
git+https://github.work.com/organization/my-dependency-sdk.git
The format I originally used was for ssh.

How to install an npm package from GitHub directly

Trying to install modules from GitHub results in this error:
ENOENT error on package.json.
Easily reproduced using express:
npm install https://github.com/visionmedia/express throws error.
npm install express works.
Why can't I install from GitHub?
Here is the console output:
npm http GET https://github.com/visionmedia/express.git
npm http 200 https://github.com/visionmedia/express.git
npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz
npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.8.0-23-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"
npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename
npm ERR! node -v v0.10.10
npm ERR! npm -v 1.2.25
npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log
npm ERR! not ok code 0
Because https://github.com/visionmedia/express is the URL of a web page and not an npm module. Use this flavor: git+{url}.git
git+https://github.com/visionmedia/express.git
or this flavor if you need SSH:
git+ssh://git#github.com/visionmedia/express.git
or if you need to install a GitHub Enterprise repository:
git+https://<github enterprise url>/<org>/<repo>.git#<branch>
To install from GitHub, you can also do
npm install visionmedia/express
Or
npm install visionmedia/express#branch
There is also support for installing directly from a Gist, Bitbucket, GitLab, and a number of other specialized formats. Look at the npm install documentation for them all.
If Git is not installed, we can try:
npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master
As of September 2016, installing from vanilla HTTPS GitHub URLs now works:
npm install https://github.com/fergiemcdowall/search-index.git
You can't do this for all modules because you are reading from a source control system, which may well contain invalid/uncompiled/buggy code. So to be clear (although it should go without saying): given that the code in the repository is in an npm-usable state, you can now quite happily install directly from GitHub.
In October 2019, we are now living through "peak TypeScript/React/Babel", and therefore JavaScript compilation has become quite common. If you need to take compilation into account, look into prepare. That said, NPM modules do not need to be compiled, and it is wise to assume that compilation is not the default, especially for older node modules (and possibly also for very new, bleeding-edge "ESNext"-y ones).
The methods are covered pretty well now in npm's install documentation as well as the numerous other answers here.
npm install git+ssh://git#github.com:<githubname>/<githubrepo.git[#<commit-ish>]
npm install git+ssh://git#github.com:<githubname>/<githubrepo.git>[#semver:^x.x]
npm install git+https://git#github.com/<githubname>/<githubrepo.git>
npm install git://github.com/<githubname>/<githubrepo.git>
npm install github:<githubname>/<githubrepo>[#<commit-ish>]
However, something notable that has changed recently is npm adding the prepare script to replace the prepublish script. This fixes a long-standing problem where modules installed via Git did not run the prepublish script and thus did not complete the build steps that occur when a module is published to the npm registry. See Run prepublish for Git URL packages #3055.
Of course, the module authors will need to update their package.json file to use the new prepare directive for this to start working.
There's also npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH} to use a different branch.
The current top answer by Peter Lyons is not relevant with recent NPM versions. For example, using the same command that was criticized in this answer is now fine.
npm install https://github.com/visionmedia/express
If you have continued problems it might be a problem with whatever package you were using.
The general form of the syntax is
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
which means for your case it will be
npm install git+ssh://git#github.com/visionmedia/express.git
From npmjs docs:
npm install :
Installs the package from the hosted git provider, cloning it with
git. For a full git remote url, only that URL will be attempted.
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish>
| #semver:] is one of git, git+ssh, git+http,
git+https, or git+file.
If # is provided, it will be used to clone exactly that
commit. If the commit-ish has the format #semver:,
can be any valid semver range or exact version, and npm will look for
any tags or refs matching that range in the remote repository, much as
it would for a registry dependency. If neither # or
semver: is specified, then master is used.
If the repository makes use of submodules, those submodules will be
cloned as well.
If the package being installed contains a prepare script, its
dependencies and devDependencies will be installed, and the prepare
script will be run, before the package is packaged and installed.
The following git environment variables are recognized by npm and will
be added to the environment when running git:
GIT_ASKPASS
GIT_EXEC_PATH
GIT_PROXY_COMMAND
GIT_SSH
GIT_SSH_COMMAND
GIT_SSL_CAINFO GIT_SSL_NO_VERIFY
See the git man page for details.
Examples:
npm install git+ssh://git#github.com:npm/npm.git#v1.0.27
npm install git+ssh://git#github.com:npm/npm#semver:^5.0
npm install git+https://isaacs#github.com/npm/npm.git
npm install git://github.com/npm/npm.git#v1.0.27
GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git#github.com:npm/npm.git npm install
You can do:
npm install git://github.com/foo/bar.git
Or in package.json:
"dependencies": {
"bar": "git://github.com/foo/bar.git"
}
This works for me and it is less typing.
npm i github:<UserName>/<RepoName>
package.json
{
"dependencies": {
"name": "github:<UserName>/<RepoName>"
}
}
Install it directly:
npm install visionmedia/express
Alternatively, you can add "express": "github:visionmedia/express" to the "dependencies" section of package.json file, then run:
npm install
You could also do
npm i alex-cory/fasthacks
or
npm i github:alex-cory/fasthacks
Basically:
npm i user_or_org/repo_name
Sometimes I need to install from a specific branch or commit.
To make things simple I just use https://gitpkg.vercel.app/
You can directly install a GitHub repository by the npm install command, like this:
npm install https://github.com/futurechallenger/npm_git_install.git --save
NOTE: In the repository which will be installed by npm command:
maybe you have to have a dist folder in you repository, according to Dan Dascalescu's comment.
You definitely have to have a package.json in your repository! Which I forget add.
Simple:
npm install *GithubUrl*.git --save
Example:
npm install https://github.com/visionmedia/express.git --save
I tried npm install git+https://github.com/visionmedia/express but that took way too long and I wasn't sure that would work.
What did work for me was - yarn add git+https://github.com/visionmedia/express.
Below piece of code worked for me to install from github repository:
npm install git+ssh://<your_repository_ssh_clone_link>#<branch_name_if_any>
You can get ssh clone link as below:
So for above screenshot repository, you may need to import as below,
npm install git+ssh://git#github.com:Siddhu2/calculator-chatbot.git#master
where master is my branch and it is optional since I have only one branch.
If you get something like this:
npm ERR! enoent undefined ls-remote -h -t https://github.com/some_repo/repo.git
Make sure you update to the latest npm and that you have permissions as well.
The only command that worked for me was npm i MY_PACKAGE_NAME:MY_REPOSITORY#BRANCH_NAME
No need to do much; this helped me:
Yarn add <git_name>:<github_name>/<Repository_name>.git
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git
And if you want to add some specific commit or branch name then add #.
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git#master
Example:
yarn add git#github.com:myGitHub/dynamic-checkbox-input.git#c978U57
Yarn 2 requires the package name along with the Github repository. Read the documentation of Yarn's CLI.
Example: yarn add <package_name>git#github.com:<owner_name>/<package_name>.git
Try this command:
npm install github:[Organisation]/[Repository]#[master/BranchName] -g
This command worked for me:
npm install github:BlessCSS/bless#3.x -g