Sonatype - Nexus Repo NPM packages URL not correct - npm

At my company, Nexus is being used to download external NPM packages as a proxy and keeping them cached. But, when I run npm install, some of the generated package URL's are not well built. Then a 404 Error is thrown because of it:
error An unexpected error occurred: "<registry>/nodemon/-/1.19.1.tgz: Request failed \"404 Not Found\"
But the URL should be:
"<registry>/nodemon/-/nodemon-1.19.1.tgz"
Can someone help?

Related

DevOps local npm ajv version has been deleted

We have an issue with devops upstream npm feed. We built and deployed our angular app a few month ago with no issues. We are now trying to build the project but its complaining the below error. This seems to be because the locally stored version of the upstream npm package, ajv version 6.12.6 has been deleted; due to a retention policy. We are unable to get it back, does anyone know how we get it back?
npm ERR! code E404
npm ERR! 404 Not Found - GET https://tfs.pkgs.visualstudio.com/_packaging/myproject/npm/registry/ajv/-/ajv-6.12.6.tgz - Cannot find the package 'ajv' in feed 'npm_***'
npm ERR! 404
npm ERR! 404 'ajv#https://tfs.pkgs.visualstudio.com/_packaging/myproject/npm/registry/ajv/-/ajv-6.12.6.tgz' is not in this registry.
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
The artifact view shows the below:
Update:
It would seem that there is no way to correct this! as mentioned here https://developercommunity.visualstudio.com/t/deleted-versions-of-upstream-packages-cannot-be-re/1620100
Fairly poor thought on DevOps part! So currently we are now pointing to the standard npm package url (https://registry.npmjs.org/) and not the dev ops artifact one; in order to get it to build again!
As you know, Azure DevOps feed has a immutability constraint. So there doesn't have any way to add the same version in the true sense at this moment.
Currently available methods are:
1, Create a new feed and download the package via this feed.
2, Download the package change the package info and publish to Artifact feed(As another package.)
3, Directly use the public source.
There is a suggestion ticket about this feature in official community:
Relax Azure Artifacts restriction on re-publishing versions
You can upvote this suggestion ticket and share your ideas in it.

yarn add - 403 (Forbidden)

I have published a private package in my company as #company/package-name, I can see it in our github repository.
After that, I did yarn add #company/package-name in another project and I got:
➤ YN0027: #company/package-name#unknown can't be resolved to a satisfying range
➤ YN0035: The remote server failed to provide the requested resource
➤ YN0035: Response Code: 403 (Forbidden)
➤ YN0035: Request Method: GET
➤ YN0035: Request URL: https://npm.pkg.github.com/#company%2fname
It is weird, I can publish but I cannot install it.
Do you have any idea please?
Finally I got the source of errors.
The checkbox Inherit access from source repository (recommended) was unchecked in the package settings page.
I have enabled it, and now, we can publish (also with --experimental) and also download this new package.
Thank you Trond Glomnes for your help.
Looks like yarn is causing issue. followed the below steps and that did the trick.
npm uninstall –g yarn
npm cache clean –force
npx create-react-app my-app

Force NPM to skip package already installed from another source

I'm trying to npm install a package from a heavily proxied Enterprise computer. One of the dependencies of this package tries to install via GitHub, which throws a 407 error.
npm ERR! /usr/bin/git ls-remote -h -t https://github.com/ethereumjs/ethereumjs-abi.git
npm ERR!
npm ERR! fatal: unable to access 'https://github.com/ethereumjs/ethereumjs-abi.git/': Received HTTP code 407 from proxy after CONNECT
I've discussed this with the team that manages these servers- even with proper proxy authentication, access to sites outside of internal registries are very uncommon as a security measure.
As an alternative, I found the package on the NPM registry, and successfully installed it using the internal mirror we have. However, it still tries to install the GitHub version as a dependency of the first package, and then the installation fails. Is there any way to prevent this? I think I've seen something about editing the package's package.json to remove the dependency, but I don't have any experience with this, so I'll only do it if it's the only option to prevent this. Thank you

Can't install a scoped package I published to a npm registry in GCP

I published several npm packages to a private npm registry hosted in GCP and I can see all versions in the registry. Yet I can't download the package since the install command throws an E404.
NPM throws a generic 404 Error when trying to download the page:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://europe-north1-npm.pkg.dev/[Project]/#[scope]/[packagename]/-/#[scope]/[packagename]-0.1.0.tgz
npm ERR! 404
npm ERR! 404 '#[scope]/[packagename]#https://europe-north1-npm.pkg.dev/[Project]/#[scope]/[packagename]/-/#[scope]/[packagename]-0.1.0.tgz' 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.
Opening the url that is tring to resolve returns this error:
{"error":"Permission \"artifactregistry.repositories.downloadArtifacts\" denied on resource \"projects/[Project]/locations/europe-north1/repositories/#[scope]\" (or it may not exist)"}
{"error":"Unmatched scope name: \"\" != \"#[scope]\""}
Additonally, I checked and my account does in fact have to downloadArtifacts role.
I can't figure out why it's unable to resolve the URL since with the same config I'm able to both publish and even run npm view the package.
I've tried creating brand new packages, specifying a version, resetting the auth token and yet for some reason I'm still unable to download packages.
If it helps, my current .npmrc file looks like this:
registry:https://registry.npmjs.org/=true
#[scope]:registry=https://europe-north1-npm.pkg.dev/[project]/[repo name]/
//europe-north1-npm.pkg.dev/[project]/[repo name]/:_authToken=[gcp auth token]
//europe-north1-npm.pkg.dev/[project]/[repo name]/:always-auth=true
//registry.npmjs.org/:_authToken=[npm auth token]
Turns out this was not a GCP specific issue, but a Yarn Berry issue when publishing to GCP.
The tarballURL that is being generated uses a truncated registry URL which is why i was getting a 404 when trying to install the package.
A fix for this was proposed here.
https://github.com/yarnpkg/berry/pull/3513
I had an error similar to this one.
I did the entire repository creation process and created a new project to test the package.
When I tried npm install my-package I got a 404 error.
After some tests I discovered that I need the .npmrc file also in the project that will consume the package. It may seem kind of obvious to some people but I didn't know.
Add the returned configuration settings to the .npmrc configuration file in your Node.js projects. This file is usually in the same directory as package.json.
Make sure that you include these settings in Node.js projects for packages that you publish as well as projects that will install dependencies from your npm repository.
Set up authentication for npm

Cloudflare Pages Deployment: Yarn install fails with 401 Unauthorized for fontawesome dependency

Deployments worked fine before I installed FontAwesome. Locally it works fine even with FontAwesome. But with FontAwesome dependency installed Cloudflare fails.
Console log from Cloudflare Pages:
23:32:59.378 Installing NPM modules using Yarn version 1.22.4
23:32:59.751 yarn install v1.22.4
23:32:59.851 [1/4] Resolving packages...
23:33:00.491 [2/4] Fetching packages...
23:33:00.802 error An unexpected error occurred: "https://npm.fontawesome.com/#fortawesome/free-solid-svg-icons/-/5.15.3/free-solid-svg-icons-5.15.3.tgz: Request failed \"401 Unauthorized\"".
23:33:00.802 info If you think this is a bug, please open a bug report with the information provided in "/opt/buildhome/repo/yarn-error.log".
23:33:00.802 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
23:33:23.195 Error during Yarn install
23:33:23.195 Failed: build command exited with code: 1
I just had this issue when trying build a Strapi app on DigitalOcean. I was able to fix it using this guide from the FontAwesome website.
Unfortunately, this workaround requires a valid auth token. Luckily for me, I was already an FA Pro subscriber.
Create an .npmrc file in the root of your project and add the below code, replacing "TOKEN" with your auth token. The auth token can be found on the guide linked above once logged into the FA website.
#fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=TOKEN
I'm not well versed enough in npm authentication to know why the free version would require this, but I'm sure there must be another workaround for free users of FA.