2
votes

I am getting weird build errors in my angular application. Can anyone point out where I am doing wrong. I am trying to integrate Azure AD authentication using ADAL.js angular package. I am using adal-angular5 for this.

cli command: ng serve

ERROR in node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'. node_modules/adal-angular5/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

when used with ng build --prod

ERROR in @angular\common\http\http.ts(62,2): Error during template compile of 'HttpClient' Function calls are not supported in decorators but 'ɵmakeDecorator' was called in 'Injectable' 'Injectable' calls 'ɵmakeDecorator'. node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'. node_modules/adal-angular5/node_modules/@angular/core/src/render3/ng_dev_mode.d.ts(9,11): error TS2451: Cannot redeclare block-scoped variable 'ngDevMode'.

Here are my angular version details

Angular CLI: 6.1.4
Node: 8.11.4
OS: win32 x64
Angular: 6.1.3
Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.4
@angular-devkit/build-angular     0.7.4
@angular-devkit/build-optimizer   0.7.4
@angular-devkit/build-webpack     0.7.4
@angular-devkit/core              0.7.4
@angular-devkit/schematics        0.7.4
@angular/cli                      6.1.4
@ngtools/webpack                  6.1.4
@schematics/angular               0.7.4
@schematics/update                0.7.4
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.9.2

my app.moudle.ts for reference:

import { AuthService } from './services/auth.service';
import { AuthGuardService } from './services/auth-gurad.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ProtectedComponent } from './protected/protected.component';
import { AuthCallbackComponent } from './auth-callback/auth- 
callback.component';
import { Adal5Service, Adal5HTTPService } from 'adal-angular5';
import { HttpClient } from '@angular/common/http';
const routes: Routes = [
{
   path:'',
   children: []
},
{
   path:'protected',
   component:ProtectedComponent,
   canActivate: [AuthGuardService]
},
{
   path:'auth-callback',
   component:AuthCallbackComponent
}
];

@NgModule({
declarations: [
  AppComponent,
  ProtectedComponent,
  AuthCallbackComponent
 ],
 imports: [
    BrowserModule,
    RouterModule.forRoot(routes)
 ],
 exports: [RouterModule],
 providers: [AuthGuardService, AuthService, Adal5Service,{ 
 provide:Adal5HTTPService, useFactory:Adal5HTTPService.factory, deps: 
 [HttpClient, Adal5Service] } ],
 bootstrap: [AppComponent]
 })

 export class AppModule { }

Here is my tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
  "baseUrl": "./",
  "outDir": "./dist/out-tsc",
  "sourceMap": true,
  "declaration": false,
  "module": "es2015",
  "moduleResolution": "node",
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "target": "es5",
  "typeRoots": [
     "node_modules/@types"
  ],
  "lib": [
  "es2017",
  "dom"
   ]
  }
 }

If any more reference needed please let me know.

1
could you please post your tsconfig.json. - Fateme Fazli
I have updated the details. Please let me know if anything is wrong. - Jyotirmaya Prusty

1 Answers

0
votes

It looks like you are trying to use Angular 6 for your project, but adal-angular5 depends on Angular 5. As a result, both Angular 5 and Angular 6 are installed, and their type definitions are conflicting; you may have problems at runtime too. Either switch your project to Angular 5 or try adal-angular4, which is supposed to support Angular 4 and newer.