You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1- install jest, ts-jest
2- create jest.config.ts that imports an esm pacjage like json-strip-comments
import strip from 'strip-json-comments'
export default function jestConfig(){
// call the esm function
strip(...);
return {
// normal jest configs here
}
}
3- add type: module in package.json
4- update tsconfig to use esm instead of commonjs
5- run jest using ts-node/esm loader and passing vm-modules
Error: Jest: Failed to parse the TypeScript config file jest.config.ts
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/.pnpm/[email protected]/node_modules/strip-json-comments/index.js from jest.config.ts not supported.
Instead change the require of index.js in jest.config.ts to a dynamic import() which is available in all CommonJS modules.
note that this behavior touches loading jest.config.ts as esm allowing importing other esm modules, not about running spec files as esm
also note that my project already configured and runs as esm, I don't use commojs at all
Version
29.7.0
Steps to reproduce
minimal reproduction
1- install jest, ts-jest
2- create jest.config.ts that imports an esm pacjage like
json-strip-comments
3- add
type: module
in package.json4- update tsconfig to use esm instead of commonjs
5- run jest using
ts-node/esm
loader and passingvm-modules
Expected behavior
load
jest.config.ts
as esmActual behavior
note that this behavior touches loading
jest.config.ts
as esm allowing importing other esm modules, not about running spec files as esmalso note that my project already configured and runs as esm, I don't use commojs at all
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: