Angular deploy to Azure static web apps not working

328 Views Asked by At

I'm trying to deploy an angular app to azure static web apps.

node version = 16.18.1
npm version = 8.8.0

Azure uses gitub actions to build and deploy the code.

When I push the code, github actions starts building the code and fails with this error:

Using Node version: 
v16.20.2

Using Npm version:
8.19.4

Running 'npm install'...

npm ERR! Invalid version

How can I fix this? How can I set npm version?

Edit:

On my local, I have to run:

npm install --legacy-peer-deps

Looks like it is failing because of this. Any solution to this?

1

There are 1 best solutions below

1
On BEST ANSWER

When I tried to implement the same in my environment, got the same error.

  • Installed "@angular/core": "^7.0.0" as Peer dependency in local.

Package.json:

{
  "name": "peerangularapp",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^16.0.0",
    "@angular/common": "^16.0.0",
    "@angular/compiler": "^16.0.0",
    "@angular/core": "^16.0.0",
    "@angular/forms": "^16.0.0",
    "@angular/platform-browser": "^16.0.0",
    "@angular/platform-browser-dynamic": "^16.0.0",
    "@angular/router": "^16.0.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.13.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^16.0.1",
    "@angular/cli": "~16.0.1",
    "@angular/compiler-cli": "^16.0.0",
    "@types/jasmine": "~4.3.0",
    "jasmine-core": "~4.6.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.0.0",
    "typescript": "~5.0.2"
  },
  "peerDependencies": {
    "@angular/core": "^7.0.0"
  }
}

enter image description here

In my case, I figured out that I was getting the error because I had @angular/core dependency in both dependencies and peer dependencies section with different versions in package.json.

  • To resolve this, I had to remove @angular/core in dependencies section and changed the version of @angular/core to 16.0.0 in peer dependencies.

(or)

  • Remove peer dependencies and add to dependencies in package.json, later those dependencies can be added manually to peer dependencies:

Able to deploy the Angular application to static web app successfully:

enter image description here

Portal:

enter image description here

Running the deployed application:

enter image description here