web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Unable to load externa...
Power Apps
Unanswered

Unable to load external JS files async, wrong path probably

(0) ShareShare
ReportReport
Posted on by 38

Hi,

 

I'm using the Scandit library and I've ran into a problem. The Scandit library requires  in the config to establish the path to the js and wasm files that will load asynchronously to work.

I put the files in the out/controls/ScanditComponent 
And the configuration simply "/"

 

That works on local in the harness, no problem there.

When I package the solution and import it and try it on a Canvas App, I get a 404 error for those 2 files.

I guess there should be a way to manage the path to the files dynamically, maybe with Webpack or something.

 

I've tried to import the files so that they're incorporated on the solution but the 'wasm' file gives an error that WebAssembly modules are not allowed and it must happen must happen asynchronous.

 

Using a CDN is no option either because the requirement is that this PCF component should be able to work offline.

 

Any help would be much appreciated 😄

Daniel

 

 

I have the same question (0)
  • Ben Thompson Profile Picture
    1,400 on at

    / gives you a path that starts at the root directory of the server, ./ (i.e. a dot or full stop before the slash) gives you a path that is relative to the component that called it and the root directory of the harness is not going to be the same as the root directory on a server so you really need to use a relative path and I suspect ./ will be enough.

     

    A CDN may also actually work as a lot of items are cached for speed and offline performs. If the relative paths solution above doesn't fix it don't rule out using a CDN without testing it.

     

     

  • DanielZZ Profile Picture
    38 on at

    Thanks for the reply @ben-thompson

     

    With the CDN it does work, but the offline functionality is not 100% reliable and is an important requirement.

     

    I forgot to mention I already tried './', or putting it in a folder like './scanditEngine' and simply 'scanditEngine' but to no avail.

    The other detail is that I'm inserting this PCF component into a CanvasApp and for some reason it seems that the bundle.js is being served from a blob, so my guess is that any file system is just gone...

     

    I'm attaching an image of the console.log error

     

    The url ./scanditEngine/ is correct but the response is a 404

     

    Any suggestions?

    scandit_error.png
  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @DanielZZ 

    Have you tried to declare the files in your manifest, in order to be able to access them using the relative path?

    Best regards,

    Diana

  • DanielZZ Profile Picture
    38 on at

    Hi @DianaBirkelbach 

     

    I tried, but one is JS not TS and the other is a wasm (WebAssembly Binary File) so no chance there.
    I guess calling them async is the way to go in this situations, but I want to call them from 'inside the solution package'

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    @DanielZZ 

    My bad, you cannot declare the js in the manifest.

    You could load the js inside your index.ts file using 

    import "./YourFile.js"; 

    but maybe you don't want to have everything included in your bundle.js...

    I also have no Idea how to declare the wasm file in the manifest.

    Maybe trying to force one of the available resource types (css, img, html or resx), but setting the url to your wasm file? 

    I've did something similar, by defining some font-awesome files (.ttf, .woff....) as "css" in my manifest, but that could be a different case.

    Best regards,

    Diana

  • Ben Thompson Profile Picture
    1,400 on at

    Not that this will help but when you decide to build a release version of the component any javascript / typescript files added as an include within the index.ts file will be merged into a single file for production use.

  • DanielZZ Profile Picture
    38 on at

    @DianaBirkelbach 

    Yes, I don't want the files in the bundle, because I do not control the script calling them.

    The idea to include the wasm in the manifest as a file different than code sounds good, but that would include it in the bundle right?

    I'm trying to give it a try, but now it just seems that I just can update the component in the CanvasApp. Do you know any tricks for that?

    I'm building, msbuild -t:restore, then msbuild. Upload, publish all customization on the upload window, I do it again directly in the solution package of the PCF. 
    When I go to the CanvasApp it asks me, not always, if I wan to update. I click yes, but it's still the same. I'm putting a version number in the PCF so I can visually know immediately.

     

    Thnaks for all your help

  • DanielZZ Profile Picture
    38 on at

    @ben-thompson 

     

    In webpack there is the chuking of the bundle, so you don't have one big file.

    Do you think it could be possible to do it here and make this extra 2 files 2 chunks?

     

    Thanks!

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @DanielZZ 

    In order to update your PCF Control, you need to increase the version in the manifest.

    Alternatively, you could use pac pcf push -pp <prefix> to upload it directly in a debug solution in your system; then you don't need to use msbuild and import the solution manually.

    The js files cannot be declared in the manifest, you need to use "import" in your index.ts file. But not every "js" works this way.

    The files like css, resx, html are not bundled, so that might be your chance with the "wasm" file, but I think it's going beyond the purpose of PCF design. 

    Best regards,

    Diana

  • Rick Wilson Profile Picture
    160 on at

    Dianas @DianaBirkelbach suggestion of adding the files as if they were css files in your ControlManifest is probably the best idea.  I also do the same thing for Font Awesome.

     

    <resources>
     <css path="fonts/fa_solid_900.woff" order="2" />
     <css path="fonts/fa_solid_900.woff2" order="2" />
     <css path="fonts/fa_solid_900.ttf" order="2" />
    </resources>

     

    To make sure your component gets updated in the canvas app do the following.

     

    Inside the Canvas App Editor.

    * File -> Save -> Publish to make sure you have published your app

    * File -> Close to complete close out your app in the editor. (* This is really important because the editor will never reload any changes unless you close and re-open the app.)

     

    For your PCF Solution

    * Increment the version attribute in the ControlManifest.Input.xml

    * Increment the version property for the solution which imports the control.

    * Import your solution with the component

     

    Inside the Canvas App Editor.

    *Open your app up again in the editor and you should be asked if you would like to upgrade the component. You can now test in the editor with your updated component.

    *To make sure the app gets updated with your component updates make an arbitrary update to the app then do a File -> Save -> Publish to make sure you have published your app. (Note: Sometimes I don't see my changes reflected right away after publishing the app, i usually give it a minute or two and hit ctrl F5 a few times to do a full refresh.

     

     

    Also just on a side note the best way i have found to then load your async javascript is by adding the script tag in your init and then doing an onload function to determine if it was loaded completely in the function that will utilize the script.

     

    Add script during the init()

    		let headerScript: HTMLScriptElement = document.createElement("script");
     headerScript.type = 'text/javascript';
    		headerScript.id = "BingMapsHeaderScript";
    		headerScript.async = true;
    		headerScript.defer = true;
    		headerScript.src=`https://www.bing.com/api/maps/mapcontrol?key=${apiKey}`;
    		headerScript.onload = () => {
    			this._bMapScriptIsLoaded = true;
    		}
    		
    		this._container.appendChild(headerScript);

     

    In the function which fire that utilizes the script you can use code like that below to ensure that the script was loaded. 

    public initMap(){
    
    		var self = this;
    		if (!this._bMapScriptIsLoaded) {			
    			setTimeout(() => {self.initMap()}, 1000);
    			return;
    		}		
    ...
    }

     

     

    --Rick

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 839

#2
Valantis Profile Picture

Valantis 533

#3
Haque Profile Picture

Haque 412

Last 30 days Overall leaderboard