1

I'm using Angular 14. I have this custom library project with this folder structure

+ projects
    + my-library
        - package.json

In package.json, I have

{
  "name": "my-library",
  "version": "7.0.0",
  "peerDependencies": {
    "@angular/common": "^14.1.2",
    "@angular/core": "^14.1.2"
  },
  "dependencies": {
    "parse-domain": "^3.0.3"
  }
}

I have my library stored in a custom repo. However, when I go and try and install this custom library in another project using

$ npm install my-library@latest --registry=https://my-custom-repo.com/storage/npm/artifacts/ --legacy-peer-deps
npm ERR! code E404
npm ERR! 404 Not Found - GET https://my-custom-repo.com/storage/npm/artifacts/parse-domain - not_found
npm ERR! 404
npm ERR! 404  'parse-domain@^3.0.3' 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.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\npm-cache\_logs\2023-04-10T18_27_45_000Z-debug-0.log

The error above indicates it is attempting to look for the custom library dependency in the custom repo, even though it is just in the normal npm repo. How do I instruct the build command to install other dependencies from npm central rather than my custom repo?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • Scope your library, then you can define a registry for that scope. See e.g. https://stackoverflow.com/q/40288843/3001761. – jonrsharpe Apr 10 '23 at 18:35
  • Not quite understanding. You're saying I should break the installation into two different parts? I did try installing the library dependency on its own and then installing the library separately but got the same error. – Dave Apr 10 '23 at 19:58

1 Answers1

1
  1. 1st solution

You can solve your problem by scoping your library. In short, your package should look not my-library, but @my-scope/my-library. Just like @angular/common. When package is scoped, you can target specific registry for specific scope in .npmrc, for example:

@my-scope:registry=https://my-custom-repo.com/storage/npm/artifacts/

But for all other packages registry will be the same (e.g. .npmrc registry field)

For more info check https://docs.npmjs.com/cli/v9/using-npm/scope

  1. 2nd solution

If you can publish all of your dependecies to your custom registry, you can ignore using scopes, puplish all packages to your registry (or just proxy to npmjs through it) and then just use your registry for all packages, for example .npmrc:

registry=https://my-custom-repo.com/storage/npm/artifacts/
  1. Manual hack

You can leave only public packages in your package json (remove my-library), then run npm i, it will work. Then u can add my-library to package and target registry to private in .npmrc:

registry=https://my-custom-repo.com/storage/npm/artifacts/

and run npm i again

Eugene Mihaylin
  • 1,736
  • 3
  • 16
  • 31