-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Problem Description
The recent release of Faker v10 introduced a breaking change by removing CommonJS support entirely, making it ESM-only. This breaks compatibility with many existing TypeScript/JavaScript projects that use Jest and
other testing frameworks in CommonJS environments.
Real-world Impact
I'm experiencing this issue in a TypeScript monorepo with the following setup:
- NestJS API (CommonJS-based)
- Database package using Faker in factories for testing
- Jest for unit testing with complex configuration (env-cmd, tsconfig-paths, etc.)
After upgrading to Faker v10, all tests fail with:
Cannot use import statement outside a module
Must use import to load ES Module: @faker-js/faker/dist/index.js
Technical Analysis
Why ESM-only is problematic:
- Jest ecosystem compatibility: Jest's ESM support is still experimental and fragile
- Complex project configurations: Projects with env-cmd, path mapping, and custom setups break
- Framework limitations: NestJS and many other frameworks still primarily use CommonJS
- Forced ecosystem migration: Requires migrating entire testing stack, not just faker
Current workarounds are insufficient:
- Transform ignore patterns: Doesn't work reliably with complex Jest setups
- Jest ESM experimental: Unstable and breaks other tooling
- Manual mocking: Defeats the purpose of using faker
- Downgrading to v9: Only temporary solution
Comparison with Other Libraries
Most mature libraries handle this transition better by maintaining dual package exports:
- TypeScript itself maintains both ESM and CommonJS
- Lodash provides separate packages
- Many testing utilities kept backward compatibility
Suggested Solution: Restore CommonJS Support
Provide dual exports like many other libraries:
{
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
}
}
}
Business Impact
This breaking change affects:
- Enterprise projects with complex testing setups
- CI/CD pipelines that suddenly fail
- Development teams forced to spend time on tooling instead of features
- Library adoption - teams may switch to alternatives
Conclusion
While ESM is the future, forcing adoption by breaking existing projects is counterproductive. The faker library is widely used in testing environments that are inherently conservative and slow to change.
Please consider restoring CommonJS support or at least providing clearer migration paths for complex real-world setups.
Environment:
- @faker-js/faker: v10.0.0
- TypeScript: 5.9.x
- Jest: 30.0.x
- Node.js: 24.3.x