{"action":"opened","issue":{"url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/1080","repository_url":"https://api.github.com/repos/dcodeIO/protobuf.js","labels_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/1080/labels{/name}","comments_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/1080/comments","events_url":"https://api.github.com/repos/dcodeIO/protobuf.js/issues/1080/events","html_url":"https://github.com/dcodeIO/protobuf.js/issues/1080","id":338805628,"node_id":"MDU6SXNzdWUzMzg4MDU2Mjg=","number":1080,"title":"Error using extend with fromJSON","user":{"login":"cusher","id":30704914,"node_id":"MDQ6VXNlcjMwNzA0OTE0","avatar_url":"https://avatars1.githubusercontent.com/u/30704914?v=4","gravatar_id":"","url":"https://api.github.com/users/cusher","html_url":"https://github.com/cusher","followers_url":"https://api.github.com/users/cusher/followers","following_url":"https://api.github.com/users/cusher/following{/other_user}","gists_url":"https://api.github.com/users/cusher/gists{/gist_id}","starred_url":"https://api.github.com/users/cusher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cusher/subscriptions","organizations_url":"https://api.github.com/users/cusher/orgs","repos_url":"https://api.github.com/users/cusher/repos","events_url":"https://api.github.com/users/cusher/events{/privacy}","received_events_url":"https://api.github.com/users/cusher/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-06T05:00:32Z","updated_at":"2018-07-06T05:00:32Z","closed_at":null,"author_association":"NONE","body":"protobuf.js version: 6.8.7 (master e8449c4)\r\n\r\nWhen calling `protobuf.Root.fromJSON` on a JSON descriptor of a proto that contains an `extend`, an error is thrown saying the extended field is a duplicate.\r\n\r\nFor example a proto like:\r\n```proto\r\nsyntax = \"proto3\";\r\npackage mypackage.options;\r\nimport \"google/protobuf/descriptor.proto\";\r\nenum Scope {\r\n    ALL = 0;\r\n    HINT = 1;\r\n}\r\nextend google.protobuf.FieldOptions {\r\n    repeated Scope scope = 12345;\r\n}\r\n```\r\n\r\nAnd the following in TypeScript:\r\n```typescript\r\nimport * as protobuf from 'protobufjs/light';\r\nimport * as Long from 'long';\r\nprotobuf.util.Long = Long;\r\nprotobuf.configure();\r\n\r\nimport * as protoDescriptor from './proto-reflection';\r\nimport {INamespace} from 'protobufjs';\r\nexport const protoRoot = protobuf.Root.fromJSON(protoDescriptor as INamespace);\r\n```\r\n\r\nResults in the error:\r\n```\r\ntype.js:331 Uncaught Error: duplicate name '.mypackage.options.scope' in Type .google.protobuf.FieldOptions\r\n    at Type.add (type.js:331)\r\n    at tryHandleExtension (root.js:266)\r\n    at Root._handleAdd (root.js:294)\r\n    at Root._handleAdd (root.js:299)\r\n    at Root._handleAdd (root.js:299)\r\n    at Namespace.onAdd (object.js:120)\r\n    at Root.add (namespace.js:243)\r\n    at Root.addJSON (namespace.js:172)\r\n    at Function.fromJSON (root.js:51)\r\n    at Object../src/app/protos-helper.ts (protos-helper.ts:13)\r\n```\r\n\r\nOne way to work around this is to modify `tryHandleExtension` in `protobufjs/src/root.js` to replace:\r\n```js\r\nextendedType.add(sisterField);\r\n```\r\nwith:\r\n```js\r\nif (!extendedType.get(sisterField.name)) {\r\n  extendedType.add(sisterField);\r\n}\r\n```"}}
{"actor":{"display_login":"cusher"}}