{"id":16293550,"url":"https://github.com/badsyntax/ts-jest-esm-packages","last_synced_at":"2025-06-21T17:05:58.075Z","repository":{"id":136895629,"uuid":"437249844","full_name":"badsyntax/ts-jest-esm-packages","owner":"badsyntax","description":"Because I KEEP WASTING SO MUCH TIME ON THIS","archived":false,"fork":false,"pushed_at":"2021-12-11T10:23:08.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T11:13:28.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/badsyntax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-11T10:21:38.000Z","updated_at":"2021-12-11T10:23:10.000Z","dependencies_parsed_at":"2023-04-14T01:31:26.902Z","dependency_job_id":null,"html_url":"https://github.com/badsyntax/ts-jest-esm-packages","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/badsyntax/ts-jest-esm-packages","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fts-jest-esm-packages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fts-jest-esm-packages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fts-jest-esm-packages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fts-jest-esm-packages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badsyntax","download_url":"https://codeload.github.com/badsyntax/ts-jest-esm-packages/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fts-jest-esm-packages/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261162066,"owners_count":23118221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T20:11:42.581Z","updated_at":"2025-06-21T17:05:52.996Z","avatar_url":"https://github.com/badsyntax.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-jest \u0026 esm packages\n\nArrg this is so annoying. I just want to consume an ESM package from `node_modules` but jest is throwing the dreaded `Jest failed to parse a file: Unexpected token 'export'` error:\n\n```console\n FAIL  src/esmPackage.test.ts\n  ● Test suite failed to run\n\n    Jest encountered an unexpected token\n\n    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.\n\n    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.\n\n    By default \"node_modules\" folder is ignored by transformers.\n\n    Here's what you can do:\n     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.\n     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript\n     • To have some of your \"node_modules\" files transformed, you can specify a custom \"transformIgnorePatterns\" in your config.\n     • If you need a custom transformation specify a \"transform\" option in your config.\n     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the \"moduleNameMapper\" config option.\n```\n\nI'm using the following jest config, which AFAIK should prevent jest from attempting to transform the package in `node_modules`, but alas:\n\n```js\nexport default {\n  testMatch: [\"**/*.test.ts\"],\n  preset: \"ts-jest/presets/default-esm\", // or other ESM presets\n  globals: {\n    \"ts-jest\": {\n      useESM: true,\n    },\n  },\n  moduleNameMapper: {\n    \"^(\\\\.{1,2}/.*)\\\\.js$\": \"$1\",\n  },\n  verbose: true,\n  transform: {},\n};\n```\n\nEven though i've set `type: \"module\"` in my `package.json` jest can't seem to \"understand\" ESM syntax. I really don't know what jest is doing behind the scenes and it's annoying.\n\nThe \"solution\" is to use `--experimental-vm-modules`. Refer to `package.json`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadsyntax%2Fts-jest-esm-packages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadsyntax%2Fts-jest-esm-packages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadsyntax%2Fts-jest-esm-packages/lists"}