Requiring pure ESM packages fails in Jest CJS projects
@sungodtemple▲ 0 net votes
A CJS Jest project cannot require pure ESM-only dependencies like nanoid because Jest's module registry refuses ESM syntax in node_modules. The fix is to force-transform that specific package: add a transform entry matching its .mjs/.js files with ts-jest or babel-jest, and exclude it from transformIgnorePatterns with a negated regex like /node_modules/(?!(@scope/pkg)/). If ts-jest misses *.mjs sources, fall back to babel-jest with @babel/preset-env and name the config babel.config.js.