{"id":17329629,"url":"https://github.com/haines/buf-cjs-esm-ts","last_synced_at":"2025-06-22T16:33:30.482Z","repository":{"id":222831794,"uuid":"758497847","full_name":"haines/buf-cjs-esm-ts","owner":"haines","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-26T21:06:44.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T05:43:11.532Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/bufbuild/protobuf-es/issues/718","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/haines.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,"zenodo":null}},"created_at":"2024-02-16T13:02:25.000Z","updated_at":"2024-02-16T13:52:00.000Z","dependencies_parsed_at":"2024-02-16T14:28:20.155Z","dependency_job_id":"8056a35f-c6fe-40c7-8a38-c842a5ee4274","html_url":"https://github.com/haines/buf-cjs-esm-ts","commit_stats":null,"previous_names":["haines/buf-cjs-esm-ts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/haines/buf-cjs-esm-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haines%2Fbuf-cjs-esm-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haines%2Fbuf-cjs-esm-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haines%2Fbuf-cjs-esm-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haines%2Fbuf-cjs-esm-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haines","download_url":"https://codeload.github.com/haines/buf-cjs-esm-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haines%2Fbuf-cjs-esm-ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261324428,"owners_count":23141724,"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-15T14:49:00.099Z","updated_at":"2025-06-22T16:33:25.442Z","avatar_url":"https://github.com/haines.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript incorrectly loads CJS types for `@bufbuild/protobuf` with `NodeNext` module resolution\n\nThis repo demonstrates an issue with the dual-package setup of `@bufbuild/protobuf`.\n\nThere is a shared library, `lib`, which contains generated code to be consumed by the application, `app`.\n\n`app` is compiled with `ESNext` module and `Bundler` module resolution, and TypeScript correctly resolves the types from the ESM directory within `@bufbuild/protobuf`.\n\n`lib` is compiled with `NodeNext` module and module resolution, and TypeScript incorrectly resolves the types from the CJS directory within `@bufbuild/protobuf`.\n\nThis leads to type errors when `app` attempts to consume messages from `lib`.\n\n```console\n$ npm install\n\n$ npm run build\n\napp/src/index.ts:8:6 - error TS2345: Argument of type 'Pet' is not assignable to parameter of type 'Message\u003cPet\u003e'.\n  Types of property 'fromJson' are incompatible.\n    Type '(jsonValue: JsonValue, options?: Partial\u003cJsonReadOptions\u003e | undefined) =\u003e Pet' is not assignable to type '(jsonValue: JsonValue, options?: Partial\u003cJsonReadOptions\u003e | undefined) =\u003e Message\u003cPet\u003e'.\n      Types of parameters 'options' and 'options' are incompatible.\n        Type 'Partial\u003cimport(\"./node_modules/@bufbuild/protobuf/dist/esm/json-format\").JsonReadOptions\u003e | undefined' is not assignable to type 'Partial\u003cimport(\"./node_modules/@bufbuild/protobuf/dist/cjs/json-format\").JsonReadOptions\u003e | undefined'.\n          Type 'Partial\u003cimport(\"./node_modules/@bufbuild/protobuf/dist/esm/json-format\").JsonReadOptions\u003e' is not assignable to type 'Partial\u003cimport(\"./node_modules/@bufbuild/protobuf/dist/cjs/json-format\").JsonReadOptions\u003e'.\n            Types of property 'typeRegistry' are incompatible.\n              Type '(import(\"./node_modules/@bufbuild/protobuf/dist/esm/type-registry\").IMessageTypeRegistry \u0026 Partial\u003cimport(\"./node_modules/@bufbuild/protobuf/dist/esm/type-registry\").IExtensionRegistry\u003e) | undefined' is not assignable to type '(import(\"./node_modules/@bufbuild/protobuf/dist/cjs/type-registry\").IMessageTypeRegistry \u0026 Partial\u003cimport(\"./node_modules/@bufbuild/protobuf/dist/cjs/type-registry\").IExtensionRegistry\u003e) | undefined'.\n\n8 ohNo(new Pet());\n       ~~~~~~~~~\n\n\nFound 1 error.\n```\n\nI think this is due to [this TypeScript issue](https://github.com/microsoft/TypeScript/issues/50466).\n\nYou can see in VS Code that within `app/src/index.ts`, \"Go to definition\" on the `Message` type takes you to `node_modules/@bufbuild/protobuf/dist/esm/message.d.ts`, whereas within `lib/src/pet/v1/pet_pb.ts`, you go to `node_modules/@bufbuild/protobuf/dist/cjs/index.d.ts`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaines%2Fbuf-cjs-esm-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaines%2Fbuf-cjs-esm-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaines%2Fbuf-cjs-esm-ts/lists"}