Skip to content

fix(jest-cjs): add allowJs for override-for-dev#87

Merged
Shinigami92 merged 1 commit intomainfrom
fix-jest-cjs-tsconfig
Mar 18, 2026
Merged

fix(jest-cjs): add allowJs for override-for-dev#87
Shinigami92 merged 1 commit intomainfrom
fix-jest-cjs-tsconfig

Conversation

@Shinigami92
Copy link
Copy Markdown
Member

@Shinigami92 Shinigami92 commented Mar 16, 2026

relates to faker-js/faker#3558

when running pnpm run all without this change, the command fails with

> faker-jest-cjs-test@0.0.0 test /Users/shinigami/OpenSource/faker-playground/playgrounds/jest-cjs
> pnpm run-s test:node10 test:node20 test:bundler


> faker-jest-cjs-test@0.0.0 test:node10 /Users/shinigami/OpenSource/faker-playground/playgrounds/jest-cjs
> jest --config jest.config.js

 FAIL  ./index.spec.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation, specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/shinigami/OpenSource/faker/dist/index.js:1
    import{a as he,b as Ge}from"./chunk-DLFRIXRT.js";import{a as Le,b as Ke}from"./chunk-IIDNU76Y.js";import{a as be,b as Oe}from"./chunk-SG2ETNFG.js";import{a as ze,b as Pe}from"./chunk-JUHLGSZW.js";import{a as Ee,b as ce}from"./chunk-7DRJL2WR.js";import{a as Ae,b as ye}from"./chunk-AZSQ5MG2.js";import{a as De,b as Ce}from"./chunk-M2GMYNZ6.js";import{a as Se,b as Me}from"./chunk-FTI27NM5.js";import{a as Re,b as Be}from"./chunk-XFW3XWU4.js";import{a as Ue,b as He}from"./chunk-MP7XPVUD.js";import{a as Ie,b as Fe}from"./chunk-DORJYDLG.js";import{a as Te,b as Ze}from"./chunk-G7H5JESI.js";import{a as oe,b as fe}from"./chunk-6XECWNCO.js";import{a as ae,b as me}from"./chunk-LJB4GB54.js";import{a as pe}from"./chunk-PR7UXRTC.js";import{a as ke,b as se}from"./chunk-7CP67WXR.js";import{a as te}from"./chunk-RQGPKGIV.js";import{a as ie,b as _e}from"./chunk-HQM4ZGNV.js";import{a as le,b as ne}from"./chunk-XZ4IJHEF.js";import{a as xe,b as de}from"./chunk-TUSF54KX.js";import{a as ue,b as Ne}from"./chunk-QS5RDW3N.js";import{a as zr,b as Pr}from"./chunk-Y2VR62ED.js";import{a as vr,b as gr}from"./chunk-XOGULYSN.js";import{a as Vr,b as Wr}from"./chunk-YOL5LYCJ.js";import{a as Yr,b as wr}from"./chunk-FXLLTZJP.js";import{a as Xr,b as jr}from"./chunk-WL32EEGD.js";import{a as qr}from"./chunk-4VOVA6R5.js";import{a as Qr,b as $r}from"./chunk-ZI6OIG4Q.js";import{a as Jr}from"./chunk-2FBUSZO7.js";import{a as re,b as ee}from"./chunk-TZQOTAQO.js";import{a as Sr,b as Mr}from"./chunk-UC7AZ7NN.js";import{a as Rr,b as Br}from"./chunk-5YKM7F3E.js";import{a as Ur,b as Hr}from"./chunk-NKSV2QWA.js";import{a as Ir,b as Fr}from"./chunk-E5RVV4XY.js";import{a as Tr,b as Zr}from"./chunk-ES3SRWKV.js";import{a as hr,b as Gr}from"./chunk-YNAAUAPQ.js";import{a as Lr,b as Kr}from"./chunk-ODH77RLE.js";import{a as br,b as Or}from"./chunk-LLH3AHKQ.js";import{a as sr}from"./chunk-WZD5JZIE.js";import{a as ir,b as _r}from"./chunk-U3HQ364I.js";import{a as lr,b as nr}from"./chunk-X5N2SJEO.js";import{a as xr,b as dr}from"./chunk-OSAJDN6W.js";import{a as ur,b as Nr}from"./chunk-LOMMFCL4.js";import{a as Er,b as cr}from"./chunk-WDEVZBWK.js";import{a as kr}from"./chunk-OOHPW6XF.js";import{a as Ar,b as yr}from"./chunk-E6H6BWEM.js";import{a as Dr,b as Cr}from"./chunk-MN6VKFF7.js";import{a as Y,b as w}from"./chunk-HM7ZL4D2.js";import{a as X,b as j}from"./chunk-CFZIV4T7.js";import{a as J,b as q}from"./chunk-7ENJND7P.js";import{a as Q,b as $}from"./chunk-XELBZUHB.js";import{a as er}from"./chunk-VQHI2WPS.js";import{a as or,b as fr}from"./chunk-QBEYNYVG.js";import{a as rr}from"./chunk-AEADLNK5.js";import{a as ar,b as mr}from"./chunk-56ZXWMFE.js";import{a as tr,b as pr}from"./chunk-3ISA6LKV.js";import{a as I,b as F}from"./chunk-LIBJZVQV.js";import{a as T,b as Z}from"./chunk-IXK5WT5B.js";import{a as h,b as G}from"./chunk-IJG62PZV.js";import{a as L,b as K}from"./chunk-QOW7T5ZA.js";import{a as b,b as O}from"./chunk-YLKHCRUN.js";import{a as z,b as P}from"./chunk-LPMRX4Q7.js";import{a as v,b as g}from"./chunk-WP5NP2IU.js";import{a as V,b as W}from"./chunk-KWG2OWYB.js";import{a as u,b as N}from"./chunk-TKPRAKPG.js";import{a as c}from"./chunk-CHENKITB.js";import{a as A,b as y}from"./chunk-U2NRMMUZ.js";import{a as D,b as C}from"./chunk-43CLAXNS.js";import{a as E}from"./chunk-BL2FLSMB.js";import{a as S,b as M}from"./chunk-62ZSKARY.js";import{a as R,b as B}from"./chunk-O3Y2SCOL.js";import{a as r}from"./chunk-NAVWDHVN.js";import{a as H}from"./chunk-G454YEGD.js";import{a as U}from"./chunk-EQ4ZKNJQ.js";import{a as e,b as a}from"./chunk-YEFCE7RY.js";import{a as m,b as t}from"./chunk-HKKF7KP7.js";import{a as p,b as k}from"./chunk-FLHDEZLL.js";import{a as s}from"./chunk-DCGQBX34.js";import{a as i,b as _}from"./chunk-DO5T4B7M.js";import{a as l,b as n}from"./chunk-IVM76JX2.js";import{a as x,b as d}from"./chunk-WHHXNEA5.js";import{a as f}from"./chunk-CVB5IQ2Y.js";import{a as ve,b as ge,c as Ve,d as We,e as Ye,f as we,g as Xe,h as je,i as Je,j as qe,k as Qe,l as $e,m as ro,n as eo,o}from"./chunk-JGM3FQGE.js";var Mf={af_ZA:a,ar:t,az:k,base:s,bn_BD:_,cs_CZ:n,cy:d,da:N,de:c,de_AT:y,de_CH:C,dv:M,el:B,en:r,en_AU:H,en_AU_ocker:F,en_BORK:Z,en_CA:G,en_GB:K,en_GH:O,en_HK:P,en_IE:g,en_IN:W,en_NG:w,en_US:j,en_ZA:q,eo:$,es:er,es_MX:fr,fa:mr,fi:pr,fr:sr,fr_BE:_r,fr_CA:nr,fr_CH:dr,fr_LU:Nr,fr_SN:cr,he:yr,hr:Cr,hu:Mr,hy:Br,id_ID:Hr,it:Fr,ja:Zr,ka_GE:Gr,ko:Kr,ku_ckb:Or,ku_kmr_latin:Pr,lv:gr,mk:Wr,nb_NO:wr,ne:jr,nl:qr,nl_BE:$r,pl:ee,pt_BR:fe,pt_PT:me,ro:pe,ro_MD:se,ru:_e,sk:ne,sl_SI:de,sr_RS_latin:Ne,sv:ce,ta_IN:ye,th:Ce,tr:Me,uk:Be,ur:He,uz_UZ_latin:Fe,vi:Ze,yo_NG:Ge,zh_CN:Ke,zh_TW:Oe,zu_ZA:Pe};var dt={af_ZA:e,ar:m,az:p,base:o,bn_BD:i,cs_CZ:l,cy:x,da:u,de:E,de_AT:A,de_CH:D,dv:S,el:R,en:f,en_AU:U,en_AU_ocker:I,en_BORK:T,en_CA:h,en_GB:L,en_GH:b,en_HK:z,en_IE:v,en_IN:V,en_NG:Y,en_US:X,en_ZA:J,eo:Q,es:rr,es_MX:or,fa:ar,fi:tr,fr:kr,fr_BE:ir,fr_CA:lr,fr_CH:xr,fr_LU:ur,fr_SN:Er,he:Ar,hr:Dr,hu:Sr,hy:Rr,id_ID:Ur,it:Ir,ja:Tr,ka_GE:hr,ko:Lr,ku_ckb:br,ku_kmr_latin:zr,lv:vr,mk:Vr,nb_NO:Yr,ne:Xr,nl:Jr,nl_BE:Qr,pl:re,pt_BR:oe,pt_PT:ae,ro:te,ro_MD:ke,ru:ie,sk:le,sl_SI:xe,sr_RS_latin:ue,sv:Ee,ta_IN:Ae,th:De,tr:Se,uk:Re,ur:Ue,uz_UZ_latin:Ie,vi:Te,yo_NG:he,zh_CN:Le,zh_TW:be,zu_ZA:ze};export{ge as Aircraft,Ye as BitcoinAddressFamily,we as BitcoinNetwork,We as CssFunction,Ve as CssSpace,eo as Faker,ve as FakerError,Xe as IPv4Network,je as Sex,Qe as SimpleFaker,e as af_ZA,Mf as allFakers,dt as allLocales,m as ar,p as az,o as base,i as bn_BD,l as cs_CZ,x as cy,u as da,E as de,A as de_AT,D as de_CH,S as dv,R as el,f as en,U as en_AU,I as en_AU_ocker,T as en_BORK,h as en_CA,L as en_GB,b as en_GH,z as en_HK,v as en_IE,V as en_IN,Y as en_NG,X as en_US,J as en_ZA,Q as eo,rr as es,or as es_MX,ar as fa,r as faker,a as fakerAF_ZA,t as fakerAR,k as fakerAZ,s as fakerBASE,_ as fakerBN_BD,n as fakerCS_CZ,d as fakerCY,N as fakerDA,c as fakerDE,y as fakerDE_AT,C as fakerDE_CH,M as fakerDV,B as fakerEL,r as fakerEN,H as fakerEN_AU,F as fakerEN_AU_ocker,Z as fakerEN_BORK,G as fakerEN_CA,K as fakerEN_GB,O as fakerEN_GH,P as fakerEN_HK,g as fakerEN_IE,W as fakerEN_IN,w as fakerEN_NG,j as fakerEN_US,q as fakerEN_ZA,$ as fakerEO,er as fakerES,fr as fakerES_MX,mr as fakerFA,pr as fakerFI,sr as fakerFR,_r as fakerFR_BE,nr as fakerFR_CA,dr as fakerFR_CH,Nr as fakerFR_LU,cr as fakerFR_SN,yr as fakerHE,Cr as fakerHR,Mr as fakerHU,Br as fakerHY,Hr as fakerID_ID,Fr as fakerIT,Zr as fakerJA,Gr as fakerKA_GE,Kr as fakerKO,Or as fakerKU_ckb,Pr as fakerKU_kmr_latin,gr as fakerLV,Wr as fakerMK,wr as fakerNB_NO,jr as fakerNE,qr as fakerNL,$r as fakerNL_BE,ee as fakerPL,fe as fakerPT_BR,me as fakerPT_PT,pe as fakerRO,se as fakerRO_MD,_e as fakerRU,ne as fakerSK,de as fakerSL_SI,Ne as fakerSR_RS_latin,ce as fakerSV,ye as fakerTA_IN,Ce as fakerTH,Me as fakerTR,Be as fakerUK,He as fakerUR,Fe as fakerUZ_UZ_latin,Ze as fakerVI,Ge as fakerYO_NG,Ke as fakerZH_CN,Oe as fakerZH_TW,Pe as fakerZU_ZA,tr as fi,kr as fr,ir as fr_BE,lr as fr_CA,xr as fr_CH,ur as fr_LU,Er as fr_SN,Je as generateMersenne32Randomizer,qe as generateMersenne53Randomizer,Ar as he,Dr as hr,Sr as hu,Rr as hy,Ur as id_ID,Ir as it,Tr as ja,hr as ka_GE,Lr as ko,br as ku_ckb,zr as ku_kmr_latin,vr as lv,ro as mergeLocales,Vr as mk,Yr as nb_NO,Xr as ne,Jr as nl,Qr as nl_BE,re as pl,oe as pt_BR,ae as pt_PT,te as ro,ke as ro_MD,ie as ru,$e as simpleFaker,le as sk,xe as sl_SI,ue as sr_RS_latin,Ee as sv,Ae as ta_IN,De as th,Se as tr,Re as uk,Ue as ur,Ie as uz_UZ_latin,Te as vi,he as yo_NG,Le as zh_CN,be as zh_TW,ze as zu_ZA};
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

    > 1 | import { faker } from '@faker-js/faker';
        | ^
      2 | import { faker as fakerDe } from '@faker-js/faker/locale/de';
      3 | import { faker as fakerFR } from '@faker-js/faker/locale/fr';
      4 | import { describe, expect, it } from '@jest/globals';

      at Runtime.createScriptFromCode (../../node_modules/.pnpm/jest-runtime@30.2.0/node_modules/jest-runtime/build/index.js:1318:40)
      at Object.<anonymous> (index.spec.ts:1:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.293 s, estimated 3 s
Ran all test suites.
 ELIFECYCLE  Command failed with exit code 1.
ERROR: "test:node10" exited with 1.
/Users/shinigami/OpenSource/faker-playground/playgrounds/jest-cjs:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  faker-jest-cjs-test@0.0.0 test: `pnpm run-s test:node10 test:node20 test:bundler`
Exit status 1
 ELIFECYCLE  Test failed. See above for more details.
ERROR: "test" exited with 1.
 ELIFECYCLE  Command failed with exit code 1.

Why this fix is needed

The Jest config in jest-cjs uses ts-jest to transform files matching ^.+\.(t|j)s$ — i.e. both .ts and .js files. The transformIgnorePatterns is configured to let @faker-js packages through, so Jest asks ts-jest to transform faker's ESM source files (which are .js files using import/export syntax).

However, ts-jest delegates to the TypeScript compiler, and TypeScript will not process .js files unless allowJs: true is set in tsconfig.json. Without it, ts-jest silently skips the transformation of faker's .js files. The untransformed ESM import statements then hit Node's CJS runtime, causing:

SyntaxError: Cannot use import statement outside a module

The fix

Adding "allowJs": true to tsconfig.json tells TypeScript (and therefore ts-jest) to actually compile/transform .js files, so faker's ESM code gets properly transpiled to CJS before Jest executes it.

TL;DR

Without allowJs With allowJs
ts-jest receives .js file Skips transformation Transforms ESM →
CJS
Node sees import { ... } from "..." const { ... } = require("...")
Result SyntaxError Tests pass

@Shinigami92 Shinigami92 self-assigned this Mar 16, 2026
@ST-DDT
Copy link
Copy Markdown
Member

ST-DDT commented Mar 17, 2026

Could you please edit the description of this PR why this change is needed and why allowJs fixes it?

@Shinigami92
Copy link
Copy Markdown
Member Author

Could you please edit the description of this PR why this change is needed and why allowJs fixes it?

ok, will do later as I then need to find out why this fixes it
I just read parts of the error message in the terminal, stopped reading, tried out, profit, moved on, didn't question back

@ST-DDT
Copy link
Copy Markdown
Member

ST-DDT commented Mar 17, 2026

If you are unable to determine the reason, then just state:

  • when this is relevant aka: fix(jest-cjs): add allowJs for override-for-dev and the transformationIgnore pattern is likely to blame
  • and that we are unable to determine why the allowJs flag helps.

@Shinigami92
Copy link
Copy Markdown
Member Author

Shinigami92 commented Mar 17, 2026

If you are unable to determine the reason, then just state:

  • when this is relevant aka: fix(jest-cjs): add allowJs for override-for-dev and the transformationIgnore pattern is likely to blame
  • and that we are unable to determine why the allowJs flag helps.

it's not that I don't want to or I'm lazy, but a wrong computer and no time issue
this evening I'm again already booked by a friend
and just by showing some activity again on GH suddenly raised some PRs by other contributors in other of my maintained repos 😶‍🌫️ and now I need to update their oidc pipelines so I can release again 🙄

@Shinigami92
Copy link
Copy Markdown
Member Author

@ST-DDT ping

Copy link
Copy Markdown
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the PR title to mention overrides-for-dev?

e.g. fix(jest-cjs): add allowJs for override-for-dev


I'm not convinced that the explanation in the description is true, as our shipped code is js as well.
But I dont want to block this PR for minor reasons.

@Shinigami92 Shinigami92 changed the title fix: jest cjs allowJs fix(jest-cjs): add allowJs for override-for-dev Mar 18, 2026
@Shinigami92 Shinigami92 merged commit 11e87c5 into main Mar 18, 2026
9 checks passed
@Shinigami92 Shinigami92 deleted the fix-jest-cjs-tsconfig branch March 18, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants