You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular11项目导入@azure/msal-angular的MSAL_CONFIG提示无导出成员

MSAL_CONFIG导入报错问题原因

你遇到的报错是@azure/msal-angular包版本迭代导致的API变更问题:

  • MSAL_CONFIG是@azure/msal-angular 1.x版本才有的导出成员,你当前使用的^2.0.0版本已经正式移除了该常量,新版本重构了配置注入逻辑,不再通过该常量传递全局MSAL配置。
正确使用方式
  1. 先移除导入语句中的MSAL_CONFIG项
  2. MSAL全局配置统一通过MsalModule.forRoot()方法传入,示例配置如下:
// 需先从@azure/msal-browser导入依赖
import { PublicClientApplication, InteractionType } from '@azure/msal-browser';
import { MsalBroadcastService, MsalGuard, MsalGuardConfiguration, MsalInterceptor, MsalInterceptorConfiguration, MsalModule } from '@azure/msal-angular';

// NgModule imports 段配置
imports: [
  MsalModule.forRoot(
    // 第一个参数为MSAL实例配置
    new PublicClientApplication({
      auth: {
        clientId: '你的应用客户端ID',
        authority: 'https://login.microsoftonline.com/你的租户ID',
        redirectUri: window.location.origin
      },
      cache: {
        cacheLocation: 'localStorage',
        storeAuthStateInCookie: false
      }
    }),
    // 第二个参数为MsalGuard配置
    {
      interactionType: InteractionType.Redirect,
      authRequest: {
        scopes: ['user.read']
      }
    } as MsalGuardConfiguration,
    // 第三个参数为MsalInterceptor配置
    {
      interactionType: InteractionType.Redirect,
      protectedResourceMap: new Map([
        ['https://graph.microsoft.com/v1.0/me', ['user.read']]
      ])
    } as MsalInterceptorConfiguration
  )
]
  1. 如果你有自定义注入获取MSAL配置的需求,2.x版本提供MSAL_INSTANCE导出常量,可以直接注入获取初始化完成的MSAL实例,代替原先MSAL_CONFIG的使用场景。

内容的提问来源于stack exchange,提问作者Agnete

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 17:36:00