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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
greenelephant
New Member

How can i use momentjs in custom visuals?

I am writing a simple custom visual and i would like to know how i could go about and use moment.js in that visual.
I saw there is a typescript def in the git-repo ->PowerBI-visuals/src/Clients/Typedefs/moment/moment.d.ts
Does that mean that moment.js is avaiable as a common lib, ready to use in custom visuals?

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@greenelephant,

 

To develop a custom visual, please use the PowerBI Custom Visual CLI Tools. There you could find the tutorial on Adding External Libraries and Installing Typings for Libraries.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
ChrisWilliams
Advocate II
Advocate II

@greenelephant Can you share some more info about how you got this working?  I added moment 2.18.1 using npm and it appears in my node_modules folder.  Moment now comes with it's own type description file, so I added the moment.d.ts file to tsconfig.json:

 

 
"files": [
    ".api/v1.7.0/PowerBI-visuals.d.ts",    
    "node_modules/moment/moment.d.ts",
    "src/visual.ts"
  ]
I then added the moment.js file to pbviz.json:
 
  "externalJS": [
    "node_modules/moment/min/moment.min.js"
  ],
However, I'm not getting any moment-related namespace in Intellisense.
 
Can you fill-in where you were able to make this work?
 

FYI:  This answer on stack overflow solved my namespace problem with moment typings: https://stackoverflow.com/a/42290662/79271

glad you found a solution. Its been a while for me that i worked with powerbi and I cant remember how i made it work now

v-chuncz-msft
Community Support
Community Support

@greenelephant,

 

To develop a custom visual, please use the PowerBI Custom Visual CLI Tools. There you could find the tutorial on Adding External Libraries and Installing Typings for Libraries.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
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.

June 2025 community update carousel

Fabric Community Update - June 2025

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