Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'MsalModule' does not appear to be an NgModule class #5173

Closed
rafagsiqueira opened this issue Sep 6, 2022 · 4 comments
Closed

'MsalModule' does not appear to be an NgModule class #5173

rafagsiqueira opened this issue Sep 6, 2022 · 4 comments
Assignees
Labels
answered Question has received "first qualified response" bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.

Comments

@rafagsiqueira
Copy link

Core Library

MSAL.js v2 (@azure/msal-browser)

Core Library Version

2.28.1

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

2.4.1

Public or Confidential Client?

Public

Description

Cannot build angular library which imports MsalModule.

Error Message

  • Compiling with Angular sources in Ivy partial compilation mode.
    ✖ Compiling with Angular sources in Ivy partial compilation mode.
    projects/etips-utils/auth/src/auth.module.ts:51:5 - error NG6002: 'MsalModule' does not appear to be an NgModule class.

51 MsalModule
~~~~~~~~~~

node_modules/@azure/msal-angular/msal.module.d.ts:5:22
5 export declare class MsalModule {
~~~~~~~~~~
This likely means that the library (@azure/msal-angular) which declares MsalModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

Msal Logs

No response

MSAL Configuration

export function msalInstanceFactory(authConfig: BrowserAuthOptions) {
  return new PublicClientApplication({
    auth: authConfig,
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
      storeAuthStateInCookie: false
    }
  });
}

Relevant Code Snippets

import {
  MsalBroadcastService,
  MsalGuard,
  MsalGuardConfiguration,
  MsalInterceptorConfiguration,
  MsalInterceptor,
  MsalModule,
  MsalService,
  MSAL_GUARD_CONFIG,
  MSAL_INSTANCE,
  MSAL_INTERCEPTOR_CONFIG
} from '@azure/msal-angular';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AuthService } from './auth.service';
import { TransparentTextDirective } from './login/transparent-text.directive';

export function msalInstanceFactory(authConfig: BrowserAuthOptions) {
  return new PublicClientApplication({
    auth: authConfig,
    cache: {
      cacheLocation: BrowserCacheLocation.LocalStorage,
      storeAuthStateInCookie: false
    }
  });
}

@NgModule({
  declarations: [LoginComponent, LogoutComponent, TransparentTextDirective],
  imports: [
    CommonModule,
    ResponsiveModule,
    IconsModule,
    MatCardModule,
    MatButtonModule,
    HttpClientModule,
    MsalModule
  ]
})
export class AuthModule {
  static forRoot(
    authConfig: BrowserAuthOptions,
    interceptorConfig: MsalInterceptorConfiguration,
    guardConfig: MsalGuardConfiguration,
  ): ModuleWithProviders<AuthModule> {
    return {
      ngModule: AuthModule,
      providers: [
        {
          provide: HTTP_INTERCEPTORS,
          useClass: MsalInterceptor,
          multi: true
        },
        {
          provide: MSAL_INSTANCE,
          useFactory: () => msalInstanceFactory(authConfig)
        },
        {
          provide: MSAL_GUARD_CONFIG,
          useValue: guardConfig
        },
        {
          provide: MSAL_INTERCEPTOR_CONFIG,
          useValue: interceptorConfig
        },
        MsalService,
        MsalGuard,
        MsalBroadcastService,
        AuthService
      ]
    };
  }
}

angular.json:
(...)
"build": {
          "builder": "@angular-devkit/build-angular:ng-packagr",
          "options": {
            "tsConfig": "projects/etips-utils/tsconfig.lib.json",
            "project": "projects/etips-utils/ng-package.json"
          },
          "configurations": {
            "production": {
              "tsConfig": "projects/etips-utils/tsconfig.lib.prod.json"
            }
          },
          "defaultConfiguration": "production"
        }
(...)
tsconfig.json:
(...)
    "target": "es2020",
    "module": "es2020",
(...)

Reproduction Steps

  1. Create a library that imports MsalModule
  2. Compile library using ng build and @angular-devkit/build-angular:ng-packagr

Expected Behavior

Library should build successfully.

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

Chrome

Regression

No response

Source

External (Customer)

@rafagsiqueira rafagsiqueira added bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. labels Sep 6, 2022
@ghost ghost added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Sep 6, 2022
@github-actions github-actions bot added msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package public-client Issues regarding PublicClientApplications labels Sep 6, 2022
@ghost ghost assigned bmahall Sep 6, 2022
@bmahall
Copy link
Contributor

bmahall commented Sep 7, 2022

@rafagsiqueira Thanks for opening this issue. What version of Angular are you using?

@ghost ghost added answered Question has received "first qualified response" Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Sep 7, 2022
@rafagsiqueira
Copy link
Author

@bmahall thank you for looking into it. I am on version 14.2.0.

@bmahall
Copy link
Contributor

bmahall commented Sep 8, 2022

@rafagsiqueira Can you try the following steps in sequence and let me know if this fixes the error you are getting:-

  1. Delete node_modules and reinstall all dependencies using npm install
  2. Add the following line in tsconfig.json:-
    "importHelpers": true
  3. Check that you are including all the relevant imports in your code file, including import { NgModule } from '@angular/core';
  4. Restart the TS server and run "ng build"

Also unrelated to the error, you need to assign a return type to the function msalInstanceFactory.

@rafagsiqueira
Copy link
Author

@bmahall we solved the issue. It seems related to the docker context. We are now building the library directly on the build agent and copying it to the docker image already built.

@ghost ghost removed the Needs: Author Feedback Awaiting response from issue author label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Question has received "first qualified response" bug-unconfirmed A reported bug that needs to be investigated and confirmed msal-angular Related to @azure/msal-angular package msal-browser Related to msal-browser package public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

2 participants