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
Cleared
Frequent Visitor

Unable to use MomentJS when creating a custom visual

I am building a custom-visul for Power BI. When I have added momentjs, my script sort of "hangs" as soon as I try to use it in my visual.ts. I dont get an error message or exepction or anything else. Using the lines below

 

console.log('Trying moment.js');
console.log(moment);
console.log('Moment-testing success');


it "stops" after outputting Trying moment.js. I have no trouble running pbiviz start.

 

These are the steps i have taken to install momentjs:

  1. Ran npm install momentjs --save
  2. Added "node_modules/moment/moment.d.ts" under files in my tsconfig.json. From my understanding, the moment.d.ts is sort of a "header"-file which only is used for autocompelte/InteliJ in my IDE, i.e. it does only include the declaration of functions, not the definition. As soon as I add this line my IDE stops complaining about not finding moment.
  3. Added "node_modules/moment/moment.js" to my pbiviz.json under externalJS (link)
  4. Added "moment": "^2.19.1", under dependencies in the package.json.

Is there something I have missed? It feels like my application cant find the actual moment.js and resolve what moment is...

1 REPLY 1
ChrisWilliams
Advocate II
Advocate II

Hi, you may have seen this thread where I posted about using moment.js in custom visuals.  It may give you a starting point.

 

To me, the issue was not so much about anything Power BI related, but instead was related to the moment namespace issues and integration with Typescript. I could never call console.log(moment) because moment was not recognized.

 

In the end, I didn't end up needing moment so I didn't work through to a final solution.

 

good luck!

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 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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