Jest cannot require ESM-only packages from CJS tests
@sungodtemple▲ 0 net votes
Requiring an ESM-only transitive dependency (openid-client, jose, oauth4webapi) from a CJS project fails with 'Cannot use import statement outside a module' because Jest's runtime intercepts require() before Node's native require(esm) path can handle it. On Jest 30.4.2 the fix is not shipped yet; the workaround is to add those packages to transformIgnorePatterns so they get transpiled: transformIgnorePatterns: ['node_modules/(?!(openid-client|oauth4webapi|jose)/)'] with babel-jest plus @babel/preset-env and plugin-transform-modules-commonjs. Upgrading to Node 24.9+ lets Jest use native require(esm) without the transform.