Blazor JSInterop – cannot find ‘functionName’ (‘functionName’ was undefined)

I am using Abp.io for a project. I have recreated this project with minimal code twice and i’m still running into this issue.

I have a function, using IJSRuntime & IJSObjectReference, that calls Azure Blob and should download a file.

However, I get the error message cannot find ‘downloadFile’ in the debugger, even though the function is in the global.js file (both on my local file and in chrome developer tools).

Visual Studio error for JSInterop

Chrome Dev tool showing functions downloadFile

For ABP, you need to add the script into their BundleContributor class and then
you have to use their CLI to bundle any new JS file into the global file. abp bundle -f.

BundleContributor

public class CWEMPBundleContributor : IBundleContributor
{
    public void AddScripts(BundleContext context)
    {
        context.Add("./scripts/file.js");
    }

    public void AddStyles(BundleContext context)
    {
        context.Add("main.css", true);
    }
}

On my Page code I call the IJSObjectReference in the OnInitializedAsync() function.

protected override async Task OnInitializedAsync()
{
    _jsModule = await JsRuntime.InvokeAsync<IJSObjectReference>("import", "./scripts/file.js");
    PayStubsList = await AzureService.GetPayStubListAsync();
    await base.OnInitializedAsync();
}

When I test this by clicking the download button, it calls this function:

private async Task Download(string name)
{
    var contentDto = await AzureService.GetFileAsync(name);
    try
    {
        await _jsModule.InvokeVoidAsync("downloadFile", contentDto.FileName, contentDto.Content);
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        throw new UserFriendlyException($"Error Downloading the File.");
    }

}

When called, it catches the exception, as it should; but I have no idea why since the functions appear in the global.js file (both locally in my code and in chrome).

global.js local

function downloadFile(n,t){const u=new Blob([t],{type:"application/octet-stream"}),r=URL.createObjectURL(u),i=document.createElement("a");i.href=r;i.download=n;i.click();URL.revokeObjectURL(r)}function viewFile(n,t){const u=new Blob([t],{type:"application/octet-stream"}),r=URL.createObjectURL(u),i=document.createElement("a");i.href=r;i.target="_blank";document.body.appendChild(i);i.click();URL.revokeObjectURL(r)};

Here is the unbundled and minified version file.js:

function downloadFile(fileName, byteArray) {
    // Convert the byte array to a Blob
    const blob = new Blob([byteArray], { type: 'application/octet-stream' });

    // Create an object URL for the Blob
    const url = URL.createObjectURL(blob);

    // Create an anchor element for the download link
    const link = document.createElement('a');
    link.href = url;
    link.download = fileName; // Set the desired file name

    // Trigger the download
    link.click();

    // Clean up the object URL
    URL.revokeObjectURL(url);
}

function viewFile(fileName, byteArray) {
    // Convert the byte array to a Blob
    const blob = new Blob([byteArray], { type: 'application/octet-stream' });

    // Create an object URL for the Blob
    const url = URL.createObjectURL(blob);

    // Create an anchor element for the download link
    const link = document.createElement('a');
    link.href = url;
    link.target = '_blank';
    document.body.appendChild(link);
    link.click();

    // Clean up the object URL
    URL.revokeObjectURL(url);
}

I have tried to clear the application cache/local storage/ and all others. I did a hard refresh on the browser, deleted all bin/obj files, did a clean and rebuild, but still get this error.

Any pointers in the right direction would be helpful!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật