Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

[pcf-1022] [Error] Control source code declares an internal module or namespace

(0) ShareShare
ReportReport
Posted on by 11

I'm creating a dataset control which will load a map via the Google Maps Javascript API and display data from each of the records in the dataset.

 

The issue I have is that, as far as I can tell, the Google Maps Javascript API library must be loaded from Google's servers at runtime by inserting a script element into the DOM as part of the control's init() method. The script element has the onload property set to execute a callback function (initMap) which creates a new instance of the google.maps.Map object and displays the map.

 

This is all fine except that I need the new google.maps.Map object to persist outside of initMap() so I can access it later from the updateView() method to manipulate the map. I've tried to achieve this by extending the Window interface to allow the creation of a global variable while maintaining strong typing, however the PCF validation script then throws an error on build.

 

Here's an example:

declare global {
    interface Window { myMapgoogle.maps.Map }
}

[pcf-1022] [Error] Control source code declares an internal module or namespace.

 

I realise I could work around the error by doing something like this:
(<any>window).myMap = new google.maps.Map(...);
but that destroys any further type checking on the map object which is what I want to avoid.
 
Is there another way to create a global variable on the window object without the PCF validation script complaining? If not, is there another way to persist the map object between initMap and updateView?
  • BenClough Profile Picture
    2 on at
    Re: [pcf-1022] [Error] Control source code declares an internal module or namespace

    God bless you for going back and writing your solution 😂

  • Rei0116 Profile Picture
    on at
    Re: [pcf-1022] [Error] Control source code declares an internal module or namespace

    Hi

    You can check here https://www.npmjs.com/package/google-maps 

  • Verified answer
    paul365 Profile Picture
    11 on at
    Re: [pcf-1022] [Error] Control source code declares an internal module or namespace

    Thanks, I must have missed that package while looking through the npm repository. It looks like it should work but I ended up finding another solution in the meantime that might be useful for someone who has a similar issue.

     

    As an example, I created an ambient declaration file (interfaces.d.ts) and put the following inside it:

     

    declare interface Window {
        myMapgoogle.maps.Map
    }
     
    This allowed me to use window.myMap while retaining strong typing and keeping both the typescript compiler and PCF validation script happy.
  • Verified answer
    Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at
    Re: [pcf-1022] [Error] Control source code declares an internal module or namespace

    I'm not an expert, but maybe there is another way to approach this using an npm Package (something like this https://www.npmjs.com/package/google-maps ) ?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 65 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 55 Super User 2025 Season 1

Overall leaderboard