angular-token icon indicating copy to clipboard operation
angular-token copied to clipboard

How to install the library having angular 14

Open vladyslav-fenchak opened this issue 3 years ago • 3 comments

Hello. I have a question about the library. The last release I see is 3 years old, however in master it is updated to be compatible with version 14 of angular. Can you tell me how I can use this library with angular 14?

Thanks.

vladyslav-fenchak avatar Jul 19 '22 09:07 vladyslav-fenchak

I haven't seen much movement in this repo recently unfortunately, so I'm not sure when/if a new version will be updated.

In general though, NPM can install packages from GitHub repos with the following syntax:

# From the main/master primary branch
npm install neroniaky/angular-token # main/master
# From a specific branch
npm install neroniaky/angular-token#branch

b-turchyn avatar Nov 04 '22 16:11 b-turchyn

@b-turchyn Were you able to actually do that for this repo and then make use of it?

When I try, it creates an angular-token-app directory in node_modules that is nothing but *.json files, *.md files, config files, etc.

image

KOVIKO avatar Nov 16 '22 03:11 KOVIKO

This prompted me to start looking for a solution—other than --force or --legacy-peer-deps—to this issue and I've found something that works for me!

As of NPM 8 (~8.3), there's been the ability to set overrides in package.json to override dependencies of your dependencies. Personally, I had no idea. 🤣 You can manually set version strings, or you can use the special character $ to reference whatever version you are currently using in dependencies.

package.json

{
  "scripts": {
    ...
  },
  "dependencies": {
    "@angular/common": "^14.2.10",
    "@angular/compiler": "^14.2.10",
    "@angular/core": "^14.2.10",
    "angular-token": "^7.0.1",
    ...
  },
  "devDependencies": {
    ...
  },
  "overrides": {
    "angular-token": {
      "@angular/common": "$@angular/common",
      "@angular/compiler": "$@angular/compiler",
      "@angular/core": "$@angular/core"
    }
  }
}

It's worth noting that the overrides section of the config does not appear to have any effect on the resulting package-lock.json/npm-shrinkwrap.json. As such, if you want to be able to run npm ci, you must include the package.json in your container. The package-lock.json/npm-shrinkwrap.json file is not enough.

I also personally found that I had to include tslint in my devDependencies for angular-token to install via this method. The error messages from NPM made this abundantly clear, however.

KOVIKO avatar Nov 17 '22 02:11 KOVIKO