angular - TypeError: ไม่สามารถอ่านคุณสมบัติของ undefined ได้ (กำลังอ่าน 'tokenType')
เรากำลังได้รับข้อผิดพลาดดังต่อไปนี้เมื่อพยายามฝังรายงานด้วยไลบรารี Power BI Angular
TypeError: Cannot read properties of undefined (reading 'tokenType')
at isSaaSEmbedWithAADToken (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:586:38)
at getModelsAndExploration (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:696:17)
at getModelsAndExplorationAndConceptualSchema (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:840:9)
at xhr.onreadystatechange (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:505:37)
นี่คือโค้ดที่เราใช้เพื่อฝังรายงาน
this.msalService.initialize().subscribe(() => {
this.msalService.acquireTokenSilent({
scopes: environment.powerBiConfig.scopes,
account: this.authService.getUser()
}).subscribe(async (result) => {
const embedConfig: pbi.service.IComponentEmbedConfiguration = {
type: 'report',
id: this.report.identifier,
accessToken: result.accessToken,
tokenType: models.TokenType.Aad,
embedUrl: 'https://app.powerbi.com/reportEmbed?navContentPaneEnabled=false',
settings: {
panes: {
filters: {
visible: false,
}
}
}
};
const defaultFilters = this.createDefaultFilters();
const powerBiReport: any = this.powerBiService.embed(this.reportContainer.nativeElement, embedConfig);
powerBiReport.on('loaded', async () => {
await powerBiReport.setFilters(defaultFilters);
});
});
});
หลังจากติดตาม stacktrace เข้าไปยังไฟล์ Power BI Embedded JS (ซึ่งเราไม่สามารถควบคุมได้) เราสามารถระบุได้แล้วว่าสิ่งใดเป็นสาเหตุของปัญหา ฟังก์ชันต่อไปนี้คาดหวังว่าจะมีการส่ง config เข้ามา:
function isSaaSEmbedWithAADToken(config) {
// Default token type is Aad (0)
const tokenType = config.tokenType || 0;
return (window.isSaasOrPaasEmbed === true) && (tokenType === 0);
}
อย่างไรก็ตาม โค้ดชิ้นที่ทำให้เกิดข้อผิดพลาดนั้นแท้จริงแล้วไม่ได้ส่งค่าคอนฟิก
if (isSaaSEmbedWithAADToken() && config.settings && config.settings.personalBookmarksEnabled) {
url += "&defaultBookmarkEnabled=true";
}
แม้ว่าเราจะทำอะไรผิดพลาดทางด้านของเรา นี่ก็เป็นข้อบกพร่องทางด้านของไมโครซอฟท์ การแก้ไขก็เพียงแค่ส่งการตั้งค่าเหมือนที่ส่วนอื่นของโค้ดกำลังทำอยู่แล้ว
มีอะไรผิดพลาดในการตั้งค่าของเราที่ทำให้เกิดปัญหานี้หรือไม่? ไฟล์ Power BI Embedded JS ดูเหมือนจะเป็นซอร์สปิด
คำตอบ #1
ปัญหาได้รับการแก้ไขที่ฝั่งของ Microsoft แล้ว https://github.com/microsoft/powerbi-client-angular/issues/66