1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular 20 : Locales extension changed .mjs -> .js. Transpilation problem with Jest

Discussão em 'Angular' iniciado por isy, Julho 11, 2025.

  1. isy

    isy Guest

    Angular 19 : Extension of locales is .mjs in @angular/common/locales.

    Angular 20 : Extension of locales is .js in @angular/common/locales.

    Jest's default configuration ignores transformation of node_modules .js files.

    In my code, I use the following :

    import localeFR from '@angular/common/locales/fr';
    registerLocaleData(localeFR);


    and it gives an error :

    C:\xxx\node_modules\@angular\common\locales\fr.js:18
    export default ["fr", [["AM", "PM"], u, u], u, [["D", "L", "M", "M", "J", "V", "S"], ["dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."], ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"], ["di", "lu", "ma", "me", "je", "ve", "sa"]], u, [["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"], ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."], ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"]], u, [["av. J.-C.", "ap. J.-C."], u, ["avant Jésus-Christ", "après Jésus-Christ"]], 1, [6, 0], ["dd/MM/y", "d MMM y", "d MMMM y", "EEEE d MMMM y"], ["HH:mm", "HH:mm:ss", "HH:mm:ss z", "HH:mm:ss zzzz"], ["{1} {0}", "{1}, {0}", "{1} 'à' {0}", u], [",", " ", ";", "%", "+", "-", "E", "×", "‰", "∞", "NaN", ":"], ["#,##0.###", "#,##0 %", "#,##0.00 ¤", "#E0"], "EUR", "€", "euro", { "ARS": ["$AR", "$"], "AUD": ["$AU", "$"], "BEF": ["FB"], "BMD": ["$BM", "$"], "BND": ["$BN", "$"], "BYN": [u, "р."], "BZD": ["$BZ", "$"], "CAD": ["$CA", "$"], "CLP": ["$CL", "$"], "CNY": [u, "¥"], "COP": ["$CO", "$"], "CYP": ["£CY"], "EGP": [u, "£E"], "FJD": ["$FJ", "$"], "FKP": ["£FK", "£"], "FRF": ["F"], "GBP": ["£GB", "£"], "GIP": ["£GI", "£"], "HKD": [u, "$"], "IEP": ["£IE"], "ILP": ["£IL"], "ITL": ["₤IT"], "JPY": [u, "¥"], "KMF": [u, "FC"], "LBP": ["£LB", "£L"], "MTP": ["£MT"], "MXN": ["$MX", "$"], "NAD": ["$NA", "$"], "NIO": [u, "$C"], "NZD": ["$NZ", "$"], "PHP": [u, "₱"], "RHD": ["$RH"], "RON": [u, "L"], "RWF": [u, "FR"], "SBD": ["$SB", "$"], "SGD": ["$SG", "$"], "SRD": ["$SR", "$"], "TOP": [u, "$T"], "TTD": ["$TT", "$"], "TWD": [u, "NT$"], "USD": ["$US", "$"], "UYU": ["$UY", "$"], "WST": ["$WS"], "XCD": [u, "$"], "XPF": ["FCFP"], "ZMW": [u, "Kw"] }, "ltr", plural];
    ^^^^^^

    SyntaxError: Unexpected token 'export'


    My understanding : Angular dependencies are ES modules. They can contain .js files. Jest only understands commonJs code, so the code has to be transpiled.

    But I don't know how to configure it with modulePathIgnorePatterns as I have some other ESM dependencies.

    I would like to exclude all .js files from transpilation, except those from @angular/common/locales.

    Something like :

    "transformIgnorePatterns": [
    "^.+\\.js$",
    "node_modules/(?!@angular\\/common\\/locales)"
    ],


    but it doesn't work, as explained in https://jestjs.io/docs/configuration#transformignorepatterns-arraystring

    I don't want to list all my ESM dependencies.

    Another solution would be to mock locales for my tests ...

    Continue reading...

Compartilhe esta Página