{"id":15655417,"url":"https://github.com/qnighy/node-cjs-interop","last_synced_at":"2026-03-10T07:04:04.947Z","repository":{"id":42375721,"uuid":"439794848","full_name":"qnighy/node-cjs-interop","owner":"qnighy","description":"Babel plugin and helper functions for interoperation between Node.js native ESM and Babel ESM","archived":false,"fork":false,"pushed_at":"2026-03-05T15:58:59.000Z","size":4989,"stargazers_count":25,"open_issues_count":13,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-05T18:49:38.532Z","etag":null,"topics":["babel-plugin","esmodules","javascript","nodejs","swc-plugin"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/qnighy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-12-19T06:44:43.000Z","updated_at":"2026-01-04T02:37:16.000Z","dependencies_parsed_at":"2023-10-01T18:00:19.243Z","dependency_job_id":"3ee42f99-6bf1-4e29-957b-1ef3aea7e9d6","html_url":"https://github.com/qnighy/node-cjs-interop","commit_stats":{"total_commits":115,"total_committers":2,"mean_commits":57.5,"dds":"0.19130434782608696","last_synced_commit":"219dd4e16c492e28d3331e4ac3dfcdd03d06b8d0"},"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"purl":"pkg:github/qnighy/node-cjs-interop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Fnode-cjs-interop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Fnode-cjs-interop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Fnode-cjs-interop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Fnode-cjs-interop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qnighy","download_url":"https://codeload.github.com/qnighy/node-cjs-interop/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qnighy%2Fnode-cjs-interop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30326893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["babel-plugin","esmodules","javascript","nodejs","swc-plugin"],"created_at":"2024-10-03T12:59:07.778Z","updated_at":"2026-03-10T07:04:04.930Z","avatar_url":"https://github.com/qnighy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `babel-plugin-node-cjs-interop`, `swc-plugin-node-cjs-interop` and `node-cjs-interop`: fix the default import interoperability issue in Node.js\n\n## The problem to solve\n\nConsider the following modules:\n\n```javascript\n// a.js\n\nexport default function greet() {\n  console.log(\"Hello, world!\");\n}\n```\n\n```javascript\n// b.js\n\nimport greet from \"a.js\";\n\ngreet();\n```\n\nThey usually work, unless the following conditions are met:\n\n- `a.js` (the module being imported) is a **simulated ESM**. That is, the module is transpiled as a CommonJS module (by Babel or TypeScript) before execution. And,\n- `b.js` (the importing module) is a **native ESM**, That is, the module is run on Node.js' native ES Module support.\n\nYou can reproduce the above condition by placing the following files:\n\n```javascript\n// a.cjs\n\n\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true,\n});\nexports.default = greet;\n\nfunction greet() {\n  console.log(\"Hello, world!\");\n}\n```\n\n```javascript\n// b.mjs\n\nimport greet from \"./a.cjs\";\n\ngreet();\n```\n\n```\n$ node ./b.mjs\n./b.mjs:3\ngreet();\n^\n\nTypeError: greet is not a function\n    at ./b.mjs:3:1\n    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)\n    at async Promise.all (index 0)\n    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)\n    at async loadESM (node:internal/process/esm_loader:88:5)\n    at async handleMainPromise (node:internal/modules/run_main:65:12)\n```\n\n## Solution 1: Babel/SWC plugin\n\nInstall the babel plugin:\n\n```\nnpm install -D babel-plugin-node-cjs-interop\n# or:\nyarn add -D babel-plugin-node-cjs-interop\n```\n\nConfigure it in your Babel configuration:\n\n```javascript\n// .babelrc.js or babel.config.js\n\nexport default {\n  presets: [\n    /* ... */\n  ],\n  plugins: [\n    // ...\n    [\n      \"babel-plugin-node-cjs-interop\",\n      {\n        packages: [\"styled-components\", \"@babel/helper-plugin-test-runner\"],\n      },\n    ],\n  ],\n};\n```\n\nSee [the package's README](./packages/babel-plugin-node-cjs-interop/README.md) for details.\n\n### SWC version\n\nThere is the plugin for SWC too. See [the package's README](./packages/swc-plugin-node-cjs-interop/README.md) for details.\n\n## Solution 2: manually inserting the wrapper\n\n```\nnpm install -D node-cjs-interop\n# or:\nyarn add -D node-cjs-interop\n```\n\n```javascript\nimport styledOrig from \"styled-components\";\nimport { interopImportCJSDefault } from \"node-cjs-interop\";\n\nconst styled = interopImportCJSDefault(styledOrig);\n```\n\nSee [the package's README](./packages/node-cjs-interop/README.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqnighy%2Fnode-cjs-interop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqnighy%2Fnode-cjs-interop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqnighy%2Fnode-cjs-interop/lists"}