{"id":16117979,"url":"https://github.com/aelbore/esm-cjs-lib-example","last_synced_at":"2026-05-01T03:35:03.198Z","repository":{"id":97376778,"uuid":"269580563","full_name":"aelbore/esm-cjs-lib-example","owner":"aelbore","description":"Example code how to publish ESM and CJS backward compatible package","archived":false,"fork":false,"pushed_at":"2020-06-05T13:50:07.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T14:58:46.888Z","etag":null,"topics":["esm","ts-node","typescript"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/aelbore.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":"2020-06-05T09:01:22.000Z","updated_at":"2020-06-13T03:13:10.000Z","dependencies_parsed_at":"2023-06-28T21:15:38.879Z","dependency_job_id":null,"html_url":"https://github.com/aelbore/esm-cjs-lib-example","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/aelbore%2Fesm-cjs-lib-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelbore%2Fesm-cjs-lib-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelbore%2Fesm-cjs-lib-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aelbore%2Fesm-cjs-lib-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aelbore","download_url":"https://codeload.github.com/aelbore/esm-cjs-lib-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247462352,"owners_count":20942826,"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":["esm","ts-node","typescript"],"created_at":"2024-10-09T20:48:10.240Z","updated_at":"2026-05-01T03:34:58.084Z","avatar_url":"https://github.com/aelbore.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esm-cjs-lib-example\nExample code how to publish ESM and CJS backward compatible package\n\nPre-requisite\n-----\n`ts-esm` loader for javascript es module and typescript\n  ```\n  npm install ts-esm --dev\n  ```\n\n## Structure\n* `./packages/my-lib-example` \n  - this is the hybrid backward compatibility, with [conditional exports](https://nodejs.org/api/esm.html#esm_conditional_exports)\n  - `yarn build.lib` to create package for hybrid package\n    - output structure\n      ```\n       ./dist/my-lib-example/\n        cjs/\n          my-lib.js\n          package.json\n        my-lib.d.ts\n        my-lib.js\n        package.json\n      ```\n    - `./dist/my-lib-example/cjs/package.json`\n      - this will indicate that `.js` file is `commonjs` file\n      - all the `.js` file with the same directory of `package.json` would treat as `commonjs`\n      ```json\n      {\n        \"type\": \"commonjs\"\n      }\n      ```\n    - `./dist/my-lib-example/package.json`\n      - `main` entry point for commonjs, this property can be overriden by `exports`\n      - `exports` property has `require` for commonjs entry point `import` for es module entry point\n      - `module` is for bundler, if `module` is not present bundler gets `main` entry point\n      - `type` property indicates that all `.js` file treat as `es` module \n        ```json\n        {\n          \"name\": \"my-package-example\",\n          \"version\": \"0.0.1\",\n          \"type\": \"module\",\n          \"main\": \"./my-lib.js\",\n          \"module\": \"./my-lib.js\",\n          \"exports\": {\n            \"require\": \"./cjs/my-lib.js\",\n            \"import\": \"./my-lib.js\"\n          },\n          \"typings\": \"./my-lib.d.ts\"\n        }\n        ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelbore%2Fesm-cjs-lib-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faelbore%2Fesm-cjs-lib-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faelbore%2Fesm-cjs-lib-example/lists"}