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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / External JavaScript Li...
Power Apps
Answered

External JavaScript Libraries in PCF (PowerApps Component Framework)

(0) ShareShare
ReportReport
Posted on by 42

Hello Experts,

I want to use external JS Libraries (google Maps) into PCF, As we know we cannot use JS files in PCF, Separate JavaScript files will not work because a PCF component is a typescript file that is converted to JavaScript as the PCF component is built. Do we need to convert External Libraries into typeScript? How can I use these external JS libraries in Index.ts? Do we have any tools to convert js to ts? Any suggestions would be highly appreciated.


Thanks & Regards

-Sri

I have the same question (0)
  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Hi @DynamicsHulk , 

     

    About including js in typescript in general:

    You can include js in typescript files. For instance if jQuery didn't had types definitions (but it has), you could declare as a global:

    import * as $ from 'jquery'

     Then you don't have the types, but you could work with it. But most of the libraries has already type definitions.

    Or you could create your own type definitions file ".d.ts".

    Maybe this link might help: https://weblog.west-wind.com/posts/2016/sep/12/external-javascript-dependencies-in-typescript-and-angular-2

    You maybe need to tell typescript to allow js, by adding allowJs to the typescript.json: 

    https://newbedev.com/typescript-how-to-import-js-file-in-typescript-code-example

     

     

    Regarding google maps, there are some workarrounds in the docs_ : https://developers.google.com/maps/documentation/javascript/using-typescript

    but I remember there could be problems. This older question  here in the forum might  help: https://powerusers.microsoft.com/t5/Power-Apps-Pro-Dev-ISV/pcf-1022-Error-Control-source-code-declares-an-internal-module/m-p/460561#M1691

     

    Hope this helps!

     

    Kind regards,

    Diana

     

     

     

     

     

  • Singapuram Profile Picture
    42 on at

    Hi Diana,

     

    I greatly appreciate your help on this.

     

    Thanks & Regards

    -Sri

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

    Hi Sri @DynamicsHulk , 

     

    Please let me know if it helps!

     

     

  • Verified answer
    Rick Wilson Profile Picture
    160 on at

    Thanks for the great into Diana!  Just to add a bit more, if you want to search for a type that is available you can go here definitelytyped.org, or just try to run the command below.  

     

    npm install --save-dev @types/the-package-name-you-are-trying-to-use

     

    If it installs the package the types are available, otherwise you can use it untyped or as Diana suggested create your own.  Also if the types are not available think about creating it yourself and giving back to the DefinitelyTyped community on GitHub.  I contributed one and the developers were very helpful in reviewing it and providing suggestions on fixes.

     

    Another think I wanted to add was using untyped packages in TSX (React).  Depending on how the package was built you will probably have to define a very simple d.ts file just for the import work.  In the example below I wanted to try out the dom-to-image-more library quickly to see if it would accomplish something I needed to do, there were no typings available and I didn't want to create them just to test it out. 

     

    • Create a "types" folder directly under the folder where you index.ts file is located. (not necessary but I like to keep all my type definitions together for my sanity)
    • Create a new d.ts file, I give mine the same name of the package I am using.  For example dom-to-image-more.d.ts
    • You only need one line in your new dom-to-image-more.d.ts file to get started using the package.

     

    declare module 'dom-to-image-more';

     

    • Within your tsx file declare your import statement

     

    import * as domtoimage from 'dom-to-image-more';​

     

    • You should now be able to utilize the package (without types available) in your code. 

     

     domtoimage.toBlob(document.getElementById('pcfContainer')!, options).then(
     (blob: Blob) => {
     var controlArea = document.getElementById('pcfContainer'); 
     popup.hide();
     saveAs(blob, 'PCFControl.png');
     });​

     

  • Singapuram Profile Picture
    42 on at

    Hi Diana,

    I have few JavaScript external libraries and I cannot convert those into TypeScript, but I do have few internal libraries I can convert those into TypeScript. Can I refer to those external Libraries and use them within the converted TypeScript code. 

    It would be really great if you can provide some sample examples of referring to external libraries in TypeScript.

     

    Thanks

    -Sri

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

    HI @DynamicsHulk , 

     

    You mean, you would like to convert your own "js" files in "ts", and add the types to it. In your own library you use external library, and there you would need to do the trick @RAWilson  showed with example? 

    Then you would have types for your own files, but not for the external library...

    Sounds like a plan.

     

    @RAWilson provided a great example, I don't think I can go better than that. 🙂

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 445

#2
WarrenBelz Profile Picture

WarrenBelz 386 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 321 Super User 2025 Season 2

Last 30 days Overall leaderboard