|
| 1 | +--- |
| 2 | +title: Overriding NPM deps |
| 3 | +description: "Don't wait/block your work till some NPM package's released, override npm dep & treat it as a temporary solution" |
| 4 | +tags: ["angular", "npm"] |
| 5 | +pubDate: Mar 03, 2023 |
| 6 | +contributedBy: "@bartosz_wasilew" |
| 7 | +--- |
| 8 | + |
| 9 | +Let's suppose we have to update our Angular version i.e. for security reasons / new features. |
| 10 | +However, some of your libraries can still use outdated Angular version. |
| 11 | + |
| 12 | +As an example we'll consider the following Angular (already updated) modules' versions: |
| 13 | + |
| 14 | +my-app => `package.json` |
| 15 | +```json |
| 16 | +"dependencies": { |
| 17 | + "@angular/common": "^14.2.0", |
| 18 | + "@angular/core": "^14.2.0", |
| 19 | + ... |
| 20 | + ... |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +While our lib contains constraints to have the following versions: |
| 25 | + |
| 26 | +my-awesome-lib => `package.json` |
| 27 | +```json |
| 28 | +"peerDependencies": { |
| 29 | + "@angular/common": "^13.3.12", |
| 30 | + "@angular/core": "^13.3.12" |
| 31 | + } |
| 32 | +``` |
| 33 | + |
| 34 | +In order to deal with this problem we can: |
| 35 | +1. Wait & block our work till our `my-awesome-lib` supports Angular components in v.`^14.2.0` 👎 |
| 36 | +2. `Override` these deps => enforce using versions we provide for the lib 🤩 |
| 37 | + |
| 38 | +In order to override our `my-awesome-lib` we'll need to include `overrides` object, with following possible configurations: |
| 39 | + |
| 40 | +```json |
| 41 | +"overrides": { |
| 42 | + "my-awesome-lib": { |
| 43 | + "@angular/common": "14.2.0", |
| 44 | + "@angular/core": "14.2.0" |
| 45 | + } |
| 46 | + } |
| 47 | +``` |
| 48 | + |
| 49 | +```json |
| 50 | +"overrides": { |
| 51 | + "my-awesome-lib": { |
| 52 | + "@angular/common": "^14.2.0", |
| 53 | + "@angular/core": "^14.2.0" |
| 54 | + } |
| 55 | + } |
| 56 | +``` |
| 57 | + |
| 58 | +```json |
| 59 | +"overrides": { |
| 60 | + "my-awesome-lib": { |
| 61 | + "@angular/common": "$@angular/common", |
| 62 | + "@angular/core": "$@angular/core" |
| 63 | + } |
| 64 | + } |
| 65 | +``` |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
0 commit comments