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

See when key Fabric features will launch and what’s already live, all in one place and always up to date. Explore the new Fabric roadmap

Reply
mrtn
Helper II
Helper II

Error when using moment.js

I am trying to use moment.js when creating a custom visual, but get the following error: 

 

Module not found: Error: Can't resolve './locale' in 'F:\XXXXX\.tmp\build'

 

This appears to be linked to a know issue with moment.js, but none of the workarounds suggested online works. Any hints on how to resolve this when developing a custom visual?

 

 

 

 

1 ACCEPTED SOLUTION

Hi, 

 

fixed the issue by migrating the project to the latest API. 

 

Found the description here somewhat helpful, although incomplete. 

https://microsoft.github.io/PowerBI-visuals/docs/how-to-guide/migrating-to-powerbi-visuals-tools-3-0... 

View solution in original post

3 REPLIES 3
dm-p
Super User
Super User

Hi @mrtn,

I've been able to get this to work through the usual means by setting up a new custom visual on SDK v3. My steps as follows:

Install moment.js into your project as a dependency, i.e.:

npm i moment

Including in my visual.ts, e.g.:

import * as moment from 'moment';

And then doing a quick sanity test in my visual constructor, e.g.:

/** Object exists? */
    console.log(moment());
/** Should return 'en' */
    console.log(moment().locale());
/** Display day of week */
    console.log(moment().format('dddd'));
/** Test additional locale for day of week */
    console.log(moment().locale('de').format('dddd'));

And I get this in my browser console (confirming moment is accessible):

image.png

If this doesn't work for you we might need to know a bit more about your situation. Are you able to share any code that reproduces the issue for you? If so, it would be useful to get a copy of your package.json (for dependencies) and pbiviz.json (for API version), just so I can verify if there are some specific issues with the combination of how these are set up in conjunction with your code.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




@dm-p Hi Daniel, I followed your suggested steps, moment works just fine when creating a new project.

 

The issue appears to be related to incompabilities in old packages, as the project is non es2015 and was created on api v1.12. I am fine with sharing anything if you have the time to look into these legacy issues.

 

I have inherited this project and the issues from someone else. 

 

 

Hi, 

 

fixed the issue by migrating the project to the latest API. 

 

Found the description here somewhat helpful, although incomplete. 

https://microsoft.github.io/PowerBI-visuals/docs/how-to-guide/migrating-to-powerbi-visuals-tools-3-0... 

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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

Top Solution Authors