{"id":16513789,"url":"https://github.com/wintercounter/commonizer","last_synced_at":"2025-10-17T21:36:13.958Z","repository":{"id":43804476,"uuid":"497230791","full_name":"wintercounter/commonizer","owner":"wintercounter","description":"Convert ESM dependencies to CommonJS","archived":false,"fork":false,"pushed_at":"2022-07-07T20:54:59.000Z","size":6,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-05T09:41:29.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wintercounter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-28T06:12:19.000Z","updated_at":"2024-01-07T01:00:37.000Z","dependencies_parsed_at":"2022-08-29T04:31:23.661Z","dependency_job_id":null,"html_url":"https://github.com/wintercounter/commonizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wintercounter%2Fcommonizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wintercounter%2Fcommonizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wintercounter%2Fcommonizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wintercounter%2Fcommonizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wintercounter","download_url":"https://codeload.github.com/wintercounter/commonizer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238597386,"owners_count":19498396,"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-11T16:10:18.925Z","updated_at":"2025-10-17T21:36:08.915Z","avatar_url":"https://github.com/wintercounter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# commonizer\n\nConvert ESM dependencies to CommonJS\n\nThe creation of package was fueled by pure rage. Developers started to ship ESM\nonly packages which are not able to work with CommonJS. This would be fine if\nNodeJS would provide full interoperability between the different module specs,\nbut instead it's breaking the ecosystem that actually was supporting this\nthrough transpilers.\n\nSome projects cannot use ESM or cannot switch easily their code to be async,\nwhich is required to import ESM modules inside CommonJS modules. There is simply\nno way for some projects to update to the latest version of some crucial\npackages, and there's no way they can patch their security vulnerabilities if\ntheir package is ESM only.\n\n`commonizer` will give an option for those in need until they can upgrade their\ncode to be ESM only as well.\n\nThis package will:\n\n- transpile ESM modules to CommonJS modules using SWC\n- remove `exports` field from their `package.json`\n\n## Usage\n\n### Installation\n\n```sh\n# Locally\nnpm i commonizer --save-dev\n\n# Globally\nnpm i commonizer -g\n```\n\n### Specifying modules to transpile\n\nInside your `package.json`, under `commonizer` property, you can specify which\nmodules you want to transpile.\n\n- You need to specify one by one.\n- It won't transpile a module's dependencies, you need to specify them\n  separately if necessary, one-by-one.\n\n```json\n{\n  \"commonizer\": [\n    \"node_modules/chalk\",\n    \"node_modules/figures\",\n    \"node_modules/figures/node_modules/escape-string-regexp\"\n  ]\n}\n```\n\n### Run `commonizer`\n\n```sh\nnpx commonizer\n```\n\n### Remove exports only, or transpile only\n\nYou may specify if you want to do the removal of `exports` field or\ntranspilation only.\n\n```json\n{\n  \"commonizer\": [\n    [\n      \"node_modules/html-void-elements\",\n      [\n        \"node_modules/parse5\",\n        {\n          \"exports\": true,\n          \"commonjs\": false\n        }\n      ]\n    ]\n  ]\n}\n```\n\nThe above example was necessary in my case because other CJS modules were trying\nto load scripts directly (eg. `parse5/lib/parse.js`) which were not listed in\nthe `exports` field and NodeJS prevents this.\n\n## FAQ\n\n### Why not transpile dependencies of a module also?\n\nTo keep it safe. Users can decide exactly what to transpile. We don't want to\ntranspile CommonJS code \"by accident\".\n\n### Why I need to specify `node_modules` also?\n\n`commonizer` will transpile any path you want, not just node_modules.\n\n### How to know which modules to specify?\n\nNodeJS will throw an error when you encounter such.\n\n```\nError [ERR_REQUIRE_ESM]: require() of ES Module /home/user/project/node_modules/esm-module/index.js\nfrom /home/user/project/my-commonjs-file.js not supported.\n```\n\nUse the path `node_modules/esm-module`.\n\n### Can I restore the original source code for a module?\n\n`commonizer` will first create a backup of the original module.\n\n`node_modules/esm-module =\u003e node_modules/esm-module__original`\n\nSimply delete the transpiled folder and rename the backup.\n\n### How safe is this method?\n\nBelow I show an example of a list I have for a bigger, mature project. Works\nwell there, but I cannot be sure it'll work in every scenario. This is a\ntemporary solution to help overcome the surfacing issues during a project's\ntransition period.\n\n```json\n{\n  \"commonizer\": [\n    \"node_modules/chalk\",\n    \"node_modules/figures\",\n    \"node_modules/figures/node_modules/escape-string-regexp\",\n    \"node_modules/is-unicode-supported\",\n    \"node_modules/react-markdown\",\n    \"node_modules/vfile\",\n    \"node_modules/vfile-message\",\n    \"node_modules/unist-util-stringify-position\",\n    \"node_modules/unified\",\n    \"node_modules/bail\",\n    \"node_modules/is-plain-obj\",\n    \"node_modules/trough\",\n    \"node_modules/remark-parse\",\n    \"node_modules/mdast-util-from-markdown\",\n    \"node_modules/mdast-util-to-string\",\n    \"node_modules/micromark\",\n    \"node_modules/micromark-util-combine-extensions\",\n    \"node_modules/micromark-util-chunked\",\n    \"node_modules/micromark-factory-space\",\n    \"node_modules/micromark-util-character\",\n    \"node_modules/micromark-core-commonmark\",\n    \"node_modules/micromark-core-gfm\",\n    \"node_modules/micromark-util-classify-character\",\n    \"node_modules/micromark-util-resolve-all\",\n    \"node_modules/decode-named-character-reference\",\n    \"node_modules/character-entities\",\n    \"node_modules/micromark-util-subtokenize\",\n    \"node_modules/micromark-factory-destination\",\n    \"node_modules/micromark-factory-label\",\n    \"node_modules/micromark-factory-title\",\n    \"node_modules/micromark-factory-whitespace\",\n    \"node_modules/micromark-util-normalize-identifier\",\n    \"node_modules/micromark-util-html-tag-name\",\n    \"node_modules/micromark-util-decode-numeric-character-reference\",\n    \"node_modules/micromark-util-decode-string\",\n    \"node_modules/remark-rehype\",\n    \"node_modules/mdast-util-to-hast\",\n    \"node_modules/unist-builder\",\n    \"node_modules/unist-util-visit\",\n    \"node_modules/unist-util-visit-parents\",\n    \"node_modules/unist-util-visit/node_modules/unist-util-visit-parents\",\n    \"node_modules/unist-util-is\",\n    \"node_modules/unist-util-position\",\n    \"node_modules/unist-util-generated\",\n    \"node_modules/mdast-util-definitions\",\n    \"node_modules/mdast-util-definitions/node_modules/unist-util-visit\",\n    \"node_modules/micromark-util-sanitize-uri\",\n    \"node_modules/micromark-util-encode\",\n    \"node_modules/property-information\",\n    \"node_modules/hast-util-whitespace\",\n    \"node_modules/space-separated-tokens\",\n    \"node_modules/comma-separated-tokens\",\n    \"node_modules/remark-gfm\",\n    \"node_modules/micromark-extension-gfm\",\n    \"node_modules/micromark-extension-gfm-autolink-literal\",\n    \"node_modules/micromark-extension-gfm-footnote\",\n    \"node_modules/micromark-extension-gfm-strikethrough\",\n    \"node_modules/micromark-extension-gfm-table\",\n    \"node_modules/micromark-extension-gfm-tagfilter\",\n    \"node_modules/micromark-extension-gfm-task-list-item\",\n    \"node_modules/mdast-util-gfm\",\n    \"node_modules/mdast-util-gfm-autolink-literal\",\n    \"node_modules/ccount\",\n    \"node_modules/mdast-util-find-and-replace\",\n    \"node_modules/mdast-util-find-and-replace/node_modules/escape-string-regexp\",\n    \"node_modules/mdast-util-find-and-replace/node_modules/unist-util-visit-parents\",\n    \"node_modules/mdast-util-gfm-footnote\",\n    \"node_modules/mdast-util-to-markdown\",\n    \"node_modules/mdast-util-gfm-strikethrough\",\n    \"node_modules/mdast-util-gfm-table\",\n    \"node_modules/markdown-table\",\n    \"node_modules/mdast-util-gfm-task-list-item\",\n    \"node_modules/rehype-raw\",\n    \"node_modules/hast-util-raw\",\n    \"node_modules/hast-util-from-parse5\",\n    \"node_modules/hast-util-from-parse5/node_modules/hastscript\",\n    \"node_modules/hast-util-from-parse5/node_modules/hast-util-parse-selector\",\n    \"node_modules/vfile-location\",\n    \"node_modules/web-namespaces\",\n    \"node_modules/hast-util-to-parse5\",\n    \"node_modules/hast-to-hyperscript\",\n    \"node_modules/zwitch\",\n    \"node_modules/html-void-elements\",\n    [\n      \"node_modules/parse5\",\n      {\n        \"exports\": true,\n        \"commonjs\": false\n      }\n    ],\n    \"node_modules/unified/node_modules/is-plain-obj\",\n    \"node_modules/mdast-util-to-hast/node_modules/mdast-util-definitions\",\n    \"node_modules/mdast-util-to-hast/node_modules/mdast-util-definitions/node_modules/unist-util-visit\",\n    \"node_modules/mdast-util-to-hast/node_modules/unist-util-visit-parents\"\n  ]\n}\n```\n\n## PS\n\nI didn't read through what I wrote here :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwintercounter%2Fcommonizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwintercounter%2Fcommonizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwintercounter%2Fcommonizer/lists"}