Search code examples
angularnpmbuild-dependencies

how to add dependency in npm package to download another npm package?


I am building an angular app's npm package which will have a dependency on another package which is already available on npm. My dependency object will look somehow like this, "dependencies": { "@angular/animations": "^6.1.0", "@angular/common": "^6.1.0", "@angular/compiler": "^6.1.0", "@angular/core": "^6.1.0", "@angular/forms": "^6.1.0", "@angular/http": "^6.1.0", "@angular/platform-browser": "^6.1.0", "@angular/platform-browser-dynamic": "^6.1.0", "@angular/router": "^6.1.0", "ars-components": "file:dist/ars-components", "core-js": "^2.5.4", "rxjs": "~6.2.0", "ssi-package2": "^1.0.0", "zone.js": "~0.8.26", **"service1": "npm i ssi-service1"** },

I want it to install service1 on installation using this command npm i ssi-service1. I have published my package but on installation time it gives an error like this;

npm ERR! Invalid tag name "npm i ssi-service1": Tags may not have any characters that encodeURIComponent encodes.

Any help to achieve this goal will be appreciated. Thanks


Solution

  • You don’t need to npm i within your package.json

    Only add the npm package with your version (like @angular) to the file:

    “ssi-service1” : “1.0.0”
    

    After that, run npm i in the root of your package.json to pull the (missing) packages.

    Or just run: npm i —save ssi-service1 from the command line and it will be added to.