microsoft-authentication-library-for-js: PublicClientApplication type mismatches

Core Library

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

Core Library Version

2.37.0

Wrapper Library

MSAL Angular (@azure/msal-angular)

Wrapper Library Version

2.5.7

Public or Confidential Client?

Public

Description

After upgrading to the above npm version I’m now getting errors about incompatible PublicClientApplication types.

Error Message

Error: src/app/provide-azure.ts:36:55 - error TS2322: Type ‘import(“C:/Users/grosch/source/repos/newlamp/web/node_modules/@azure/msal-browser/dist/app/PublicCli entApplication”).PublicClientApplication’ is not assignable to type ‘import(“C:/Users/grosch/source/repos/newlamp/web/node_modules/@microsoft/mgt-msal2-provider /node_modules/@azure/msal-browser/dist/app/PublicClientApplication”).PublicClientApplication’. Types have separate declarations of a private property ‘activeSilentTokenRequests’.

36 Providers.globalProvider = new Msal2Provider({publicClientApplication}) ~~~~~~~~~~~~~~~~~~~~~~~

Error: src/app/provide-azure.ts:55:55 - error TS2322: Type ‘import(“C:/Users/grosch/source/repos/newlamp/web/node_modules/@azure/msal-browser/dist/app/PublicCli entApplication”).PublicClientApplication’ is not assignable to type ‘import(“C:/Users/grosch/source/repos/newlamp/web/node_modules/@microsoft/mgt-msal2-provider /node_modules/@azure/msal-browser/dist/app/PublicClientApplication”).PublicClientApplication’.

55 Providers.globalProvider = new Msal2Provider({publicClientApplication}) ~~~~~~~~~~~~~~~~~~~~~~~

Msal Logs

No response

MSAL Configuration

{
    auth: {
        clientId: environment.azure.clientId,
        authority: 'https://login.microsoftonline.com/...',
        redirectUri: window.location.origin
    },
    cache: {
        cacheLocation: BrowserCacheLocation.LocalStorage,
        storeAuthStateInCookie: false
    }
}

Relevant Code Snippets

const publicClientApplication = new PublicClientApplication({
    auth: {
        clientId: environment.azure.clientId,
        authority: 'https://login.microsoftonline.com/...',
        redirectUri: window.location.origin
    },
    cache: {
        cacheLocation: BrowserCacheLocation.LocalStorage,
        storeAuthStateInCookie: false
    }
})

export const provideAzure = () => makeEnvironmentProviders([{
    provide: APP_INITIALIZER,
    useFactory: (msalService: MsalService) => async () => {
        Providers.globalProvider = new Msal2Provider({publicClientApplication})

Reproduction Steps

Just trying to compile the code.

Expected Behavior

Not a compiler error.

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

Chrome

Regression

Not sure which version it was on previously.

Source

External (Customer)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15

Most upvoted comments

This issue is still happening and can be easily reproduced, why is it closed if the problem still hasn’t been resolved?

This code is sufficient to see the type mismatch:

import { PublicClientApplication } from '@azure/msal-browser'
import { Msal2Provider } from '@microsoft/mgt-msal2-provider'
const msalInstance = new PublicClientApplication({<your sample config>})
msalInstance.initialize().then(async () => {
  const msal2Provider = new Msal2Provider({
    publicClientApplication: msalInstance,
  })
})

It is currently happening for

"@azure/msal-browser": "^4.5.1",
"@azure/msal-react": "^3.0.5",
"@microsoft/mgt-msal2-provider": "^4.4.0",
"@microsoft/mgt-react": "^4.4.0"

@IMBeniamin Yes, these libraries are incredibly painful to work with, and cause issues every time I want to upgrade something. I tried going to version 4 like you and and it didn’t work at all, so I went back, but essentially what you have to do is add this to your package.json:

  "resolutions": {
    "@azure/msal-angular": "^3.0.10",
    "@azure/msal-browser": "^3.7.0",
    "@microsoft/mgt-msal2-provider": "^3.1.3",
  },
  "overrides": {
    "@azure/msal-angular": "^3.0.10",
    "@azure/msal-browser": "^3.7.0",
    "@microsoft/mgt-msal2-provider": "^3.1.3",
  }

That way, whether someone uses yarn or npm, it’ll force those versions in the other packages that try to reference them and you won’t get the errors.