Error: Unable to use locale for cultural change due to moment.defineLocale not being a recognized function

I am successfully using moment.js in my client-side JavaScript component built with typescript and webpack. Here are the versions of the components I am using:

 "dependencies": {
    "circular-dependency-plugin": "^5.2.2",
    "ignore-loader": "^0.1.2",
    "moment": "^2.29.1",
    "moment-locales-webpack-plugin": "^1.2.0",
    "ts-loader": "^9.2.3",
    "typescript": "^4.3.5",
    "webpack": "^5.45.1",
    "webpack-cli": "^4.7.2",
    "webpack-dev-server": "^4.0.0-beta.3"
  }

To add Persian culture to my setup as shown in this example, I needed to include the following code:

import * as moment from "moment";
import "moment/locale/fa";

console.log(moment.locale()); // en
moment.locale("fa");
console.log(moment.locale()); // should be fa

However, I am currently experiencing an error which you can see here: https://i.sstatic.net/0rzpc.png
I suspect that webpack's extra processing of .js files and simulating the require() method might be causing this issue. I have searched for similar questions but haven't found any useful answers. Can someone help me identify the problem and configure webpack to resolve it?

UPDATE:

After spending hours going through my code, I discovered a temporary solution by changing the path from ../moment to moment in the related .js setting file for languages like Persian, as seen here: https://i.sstatic.net/HybUF.png

This workaround is not ideal, so I am seeking advice on how to solve this without modifying the moment source code. Perhaps tweaking path routing in tsc or webpack configuration could help. Any suggestions would be appreciated. Thank you.

Answer №1

The feature of moment.js that supports moment.locale() was introduced in version 2.8.0.

Starting from v2.8.1, calling moment.locale('en') will set the localization without returning a moment object.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to trigger ng-click on dynamically generated elements

I have been working on an Angular function that adds a new slide when clicked with a ng-click event. var addSlide = function($scope, slideIndex, $event) { slideIndex++; var slider = angular.element('.slick-slider'); var currentSlide = slid ...

Limit an object to only contain interface properties

Suppose we have the following object: o {a : 1, b : 2} and this interface defined as: interface MyInterface { a : number } We are now looking to create a new object that represents the "intersection" of o and the MyInterface: o2 : {a : 1} The mai ...

Storing a Bootstrap form generated through a form builder into a MySQL database

I have created a form using Bootstrap 2 Form Builder and now I am looking to save the form in JSON format into a MySQL database. However, I am unsure of where to begin with this process. I was able to successfully create the form, but saving it for futur ...

Is there a way to manipulate the parent HTML element based on the output value sent to my component?

Within my codebase, I am utilizing two components - HrComponent and appcomponent. How can I effectively manage the boolean value IsBoolean from my HrComponent? HrComponent @Input()LoginName: string; IsBoolean: boolean = false; @Output()BooleanExp: ...

Issues with nodemon and nodejs in the Windows profile are causing functionality problems

Recently, I've been relying on nodemon utility to assist me with my nodejs development tasks. However, I encountered a problem after changing my profile on my Windows PC - now I can't seem to use nodemon at all... I tried reinstalling it using t ...

Summing up similar values of elements in an array (JavaScript) using Angular

My Current Tools Angular 5 AngularFire5 Firebase & Firestore My Goal I aim to iterate through an array containing objects. If a specific value in one object matches the same value in another object, I want to add their corresponding values togethe ...

The functionality of the Dropdown feature may present limitations in Laravel Blade, however, it performs excellently on any other text

There seems to be an issue with the dropdown functionality in Laravel Blade. It works as expected in other editors, as you can see from the code below. I am using Bootstrap 5.0.2 <!DOCTYPE html> <html lang="en"> <head> <meta ...

Integrating various object properties in Angular's select ng-options: A comprehensive guide

I need to merge text and number properties from JSON to display as select options values by default. The expected output should be: 000.000.0001 - Chicago HTML: <!doctype html> <html ng-app="plunker" > <head> <meta charset="utf-8"& ...

Using jQuery UI to trigger Highlight/Error animations

Apologies if this question seems obvious, but I can't seem to find a clear answer anywhere... Is there a way to add a highlight/error message similar to the ones on the bottom right of this page: http://jqueryui.com/themeroller/ by simply using a jQu ...

Troubleshooting problems with the Quora pixel after refreshing the page

Having a strange issue with the Quora pixel integration on Angular. I have added the script in the HTML code as follows: ! function(q, e, v, n, t, s) { if (q.qp) return; n = q.qp = function() { n.qp ? n.qp.apply(n, arguments) : n.queue.push ...

The removal of the Button class does not result in immediate rendering

I built a Vue application that displays a button on the screen using Bulma for styling. Upon page load, the button is correctly styled with solid red color and white text since the "is-outlined" class is not present. However, when I click the button, it sh ...

Is it recommended to use Promise.await over async/await?

After starting some new operations in my project, I discovered that db.aggregate needed to be executed asynchronously: db.aggregate( [ { $match: { "records": { $e ...

Error: TypeScript React Google Maps: The object 'google' is not recognized

After successfully loading the Google Maps JavaScript API in the public/index.html, I can log window.google.maps without any issues in the dev tools console. https://i.sstatic.net/XqeG5.png However, TypeScript seems unaware of its presence, resulting in ...

Twilio's phone calls are programmed to end after just 2 minutes

For the past week, I've been dealing with a frustrating issue where calls are being automatically disconnected after 2 minutes of recording. Here is the TwiML code: <Response> <Say voice="woman" language="en">Hii Welcome to our App</Sa ...

Concerning the intersection of PHP and javascript paths

I am currently working on a project where I have implemented a single video on the homepage as a slider. Everything looks good in the design phase, but when transitioning to core PHP development, the video no longer shows up. This is because in the desig ...

Tips for expanding button width in 'react-native-swipeout' to enable swipe action on ListView row (React Native)

Currently, I am exploring how to implement the component found here: https://github.com/dancormier/react-native-swipeout My goal is to have the row swiped all the way. Is there a method to increase the button width so that it covers the entire width of th ...

VueJS 3 custom Checkbox fails to update UI upon clicking

I'm attempting to implement a customized checkbox using Vue 3 and the composition API based on this example. However, despite confirming through devtools that all my props and bound data are successfully passed from the parent component to the child c ...

Retrieving the response value in AngularJS with $resource

I'm trying to retrieve the response of a request using $resource in AngularJS. Here is an example implementation: angular.module('app').factory('AuthResource', ['$resource', function($resource) { return { isA ...

Tips for transferring data between PHP and JavaScript

I'm in the process of designing a dynamic forum and have successfully implemented storing form details using ajax. However, I want to display the data on the page without having to reload it. Is this possible? Here is my HTML code: <form class="c ...

Tips on incorporating esbuild extensions in the template.yaml file of AWS SAM

Currently, my TypeScript Lambda functions are managed using the AWS Serverless Application Model (SAM), and I rely on esbuild for the build process. I'm interested in incorporating esbuild plugins into my build process to enable support for TypeScrip ...