Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
stevensi1018
Regular Visitor

Uncaught ReferenceError: pbi is not defined

I'm trying to put my report on my web application but I keep getting multiple errors. I found the following code online. I already have my accessToken in another variable in my web page but everytime I use an embededURL (https://embedded.powerbi.com/appTokenReportEmbed?reportId=02e45bd6-89fe-4ce6-8240-67ec73b178fc in this case) I get the following error: "Uncaught ReferenceError: pbi is not defined". Is there something I forgot to include?

 

I want to keep this as simple as possible. I want to execute this code in my web page in javascript

 

This line: let powerbi = new pbi.service.Service(pbi.factories.hpmFactory, pbi.factories.wpmpFactory, pbi.factories.routerFactory); was not there before but I added this due to forum posts. If i remove it, the error would be "powerbi is not defined"

 

 

var el = document.getElementById("bEmbedReportAction");
    if (el.addEventListener) {
        el.addEventListener("click", updateEmbedReport, false);
    } else {
        el.attachEvent('onclick', updateEmbedReport);
    }

    // handle server side post backs, optimize for reload scenarios
    // show embedded report if all fields were filled in.
    /*var accessTokenElement = document.getElementById('MainContent_accessTokenTextbox');
    if (accessTokenElement !== null) {
        var accessToken = accessTokenElement.value;
        if (accessToken !== "")
            updateEmbedReport();
    }*/
// update embed report
function updateEmbedReport() {

    // check if the embed url was selected
    var embedUrl = document.getElementById('tb_EmbedURL').value;
    alert(embedUrl);
    if (embedUrl === "")
        return;

    // Embed configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    var config = {
        type: 'report',
        accessToken: accessToken,
        embedUrl: embedUrl
    };

    // Grab the reference to the div HTML element that will host the report.
    var reportContainer = document.getElementById('reportContainer');

    // Embed the report and display it within the div container.
    let powerbi = new pbi.service.Service(pbi.factories.hpmFactory, pbi.factories.wpmpFactory, pbi.factories.routerFactory);
    var report = powerbi.embed(reportContainer, config);

    // report.on will add an event handler which prints to Log window.
    report.on("error", function (event) {
        var logView = document.getElementById('logView');
        logView.innerHTML = logView.innerHTML + "Error<br/>";
        logView.innerHTML = logView.innerHTML + JSON.stringify(event.detail, null, "  ") + "<br/>";
        logView.innerHTML = logView.innerHTML + "---------<br/>";
    });

 

Can someone helps me with this ? 

 

1 ACCEPTED SOLUTION

I fixed this by including <script type="text/javascript" src="(server name)/public/assets/js/powerbi.js""></script> this in my script.

View solution in original post

2 REPLIES 2
Eric_Zhang
Microsoft Employee
Microsoft Employee

@stevensi1018

I don't know about Typescript or Angular, however per my research, that error "Uncaught ReferenceError: pbi is not defined" is a common issue, which indicates the powerbi-client may not be correctly referenced in this case. As to the solution, you can the common solutions.

 

@MawashiKid may have more constructive advice.

I fixed this by including <script type="text/javascript" src="(server name)/public/assets/js/powerbi.js""></script> this in my script.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.