protoc-gen-ts: TypeError: Cannot read property 'hasOwnProperty' of null

Attempting to use this plugin with grpc-tools from grpc-node package:

protoc \
  --proto_path=proto/schemas \
  --plugin=protoc-gen-grpc="$(which grpc_node_plugin)" \
  --js_out=import_style=commonjs,binary:proto/js \
  --ts_out="proto/js" \
  --grpc_out=grpc_js:proto/js \
  ./proto/schemas/*.proto

Results in:

/home/cmcdragonkai/Projects/js-polykey/node_modules/typescript/lib/typescript.js:12449
        return array.hasOwnProperty("pos") && array.hasOwnProperty("end");
                     ^

TypeError: Cannot read property 'hasOwnProperty' of null
    at Object.isNodeArray (/home/cmcdragonkai/Projects/js-polykey/node_modules/typescript/lib/typescript.js:12449:22)
    at createNodeArray (/home/cmcdragonkai/Projects/js-polykey/node_modules/typescript/lib/typescript.js:20812:25)
    at Object.createCallExpression (/home/cmcdragonkai/Projects/js-polykey/node_modules/typescript/lib/typescript.js:22099:95)
    at Object.createCall (/home/cmcdragonkai/Projects/js-polykey/node_modules/typescript/lib/typescript.js:3022:29)
    at createToObject (/home/cmcdragonkai/Projects/js-polykey/node_modules/protoc-gen-ts/index.js:49:14)
    at createMessage (/home/cmcdragonkai/Projects/js-polykey/node_modules/protoc-gen-ts/index.js:1016:5)
    at processMessageDescriptor (/home/cmcdragonkai/Projects/js-polykey/node_modules/protoc-gen-ts/index.js:1545:5)
    at processProtoDescriptor (/home/cmcdragonkai/Projects/js-polykey/node_modules/protoc-gen-ts/index.js:1590:12)
    at main (/home/cmcdragonkai/Projects/js-polykey/node_modules/protoc-gen-ts/index.js:1680:24)
    at Object.<anonymous> (/home/cmcdragonkai/Projects/js-polykey/node_modules/protoc-gen-ts/index.js:1765:1)
--ts_out: protoc-gen-ts: Plugin failed with status code 1.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (9 by maintainers)

Most upvoted comments

Hey @paul-pop. I’ll try to release it today.

Hey @CMCDragonkai. in lock file we have ^3.8.3 and i think it ought to work with 4.x.x.

But we have something else to fix here. as far as i can see that you are trying to use this with other plugins. I guess you understood the plugin wrong. You don’t need any other JS related plugins if you are using this plugin.

so instead of you way you should use it like this;

protoc --proto_path=proto/schemas --ts_out="proto/ts" ./proto/schemas/*.proto

it will generate everything to the ‘proto/ts’ directory. you can import those files and they are ready to use. keep in mind that in that directory theres .ts files instead of .d.ts files which means they contain all the necessary runtime code to run. I would like assist you further if you can’t get out of this situation.