Jan69
Jan69

Reputation: 1139

Cannot find namespaces

I am using ADAL in my Angular 2 App for authentication

Getting the below error while compiling.

ERROR in C:/abc/src/app/services/adal.service.ts (5,26): Cannot find namespace 'adal'.

ERROR in C:/abc/src/app/services/adal.service.ts (5,61): Cannot find name 'AuthenticationContext'.

ERROR in C:/abc/src/app/services/adal.service.ts (10,22): Cannot find namespace 'adal'.
webpack: Failed to compile.


adal.service.ts
----------------------------
import {ConfigService} from './config.service';
import {Injectable} from '@angular/core';

import 'expose-loader?AuthenticationContext!../../../node_modules/adal-angular/lib/adal.js'; 
let createAuthContextFn: adal.AuthenticationContextStatic = AuthenticationContext; 

@Injectable()
export class AdalService {

    private context: adal.AuthenticationContext; 

Am i missing any imports ?

Upvotes: 3

Views: 1723

Answers (2)

Lars Gyrup Brink Nielsen
Lars Gyrup Brink Nielsen

Reputation: 4105

Maybe you need TypeScript definitions. Try installing with npm install --save-dev @types/adal in your project's root directory.

Another possible solution:

import * as adal from 'expose-loader?AuthenticationContext!../../../node_modules/adal-angular/lib/adal.js'

or

import {ConfigService} from './config.service';
import {Injectable} from '@angular/core';

import { adal, AuthenticationContext, AuthenticationContextStatic } from 'expose-loader?AuthenticationContext!../../../node_modules/adal-angular/lib/adal.js'; 
let createAuthContextFn: AuthenticationContextStatic = AuthenticationContext; 

@Injectable()
export class AdalService {
    private context: AuthenticationContext;
}

Upvotes: 1

Jan69
Jan69

Reputation: 1139

Fixed this issue by adding the below code in .angular-cli.json

"scripts": [
        "../node_modules/adal-angular/lib/adal.js"
      ]

Upvotes: 0

Related Questions