grpcc icon indicating copy to clipboard operation
grpcc copied to clipboard

TypeError: Cannot read property 'ns' of null

Open vanhumbeecka opened this issue 7 years ago • 4 comments

While executing the basic gprcc command on Mac OS Sierra: grpcc --proto <file> --address 127.0.0.1:<port>

I'm getting the following errors

TypeError: Cannot read property 'ns' of null
    at Object.load (/usr/local/lib/node_modules/grpcc/node_modules/grpc/src/node/index.js:152:28)
    at createClient (/usr/local/lib/node_modules/grpcc/lib/index.js:16:21)
    at Object.<anonymous> (/usr/local/lib/node_modules/grpcc/bin/grpcc.js:30:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)

Update: This only happens when the 'file' path is absolute.

When using a relative path, like the following command, I get an other error. This seems because of an import statement of an other proto file in the referenced file. The import statement is relative by itself, but it uses the base-path from where you run the gprcc-command, instead of the base-path of the file where the import statement occurs

Error: failed to import '/Users/andries/projects/google/protobuf/timestamp.proto' in './node_modules/fabric-client/lib/protos/peer/chaincode.proto': file not found
    at Error (native)
    at Builder.ProtoBuf.Builder.BuilderPrototype.import (/usr/local/lib/node_modules/grpcc/node_modules/protobufjs/dist/protobuf.js:4720:35)
    at Object.ProtoBuf.loadJson (/usr/local/lib/node_modules/grpcc/node_modules/protobufjs/dist/protobuf.js:5225:26)
    at Object.ProtoBuf.loadProto (/usr/local/lib/node_modules/grpcc/node_modules/protobufjs/dist/protobuf.js:5128:25)
    at Object.ProtoBuf.loadProtoFile (/usr/local/lib/node_modules/grpcc/node_modules/protobufjs/dist/protobuf.js:5174:52)
    at Object.load (/usr/local/lib/node_modules/grpcc/node_modules/grpc/src/node/index.js:141:26)
    at createClient (/usr/local/lib/node_modules/grpcc/lib/index.js:16:21)
    at Object.<anonymous> (/usr/local/lib/node_modules/grpcc/bin/grpcc.js:30:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)

The import statement in the supplied proto-file is

import "../google/protobuf/timestamp.proto";

The simple work-around is to navigate to the directory where the proto-file is, and executing: grpcc --proto ./chaincode.proto --address 127.0.0.1:7051

I guess it is possible to fix?

vanhumbeecka avatar Jun 16 '17 10:06 vanhumbeecka

Same thing happens to me. Would be good to be able to run this tool with absolute file names

adamcohen avatar Jul 31 '17 07:07 adamcohen

Have you tried using the --directory option? We added that for situations like this, when you want to specify a working directory outside of your current one. Please re-open if it's still an issue - thanks!

njpatel avatar Oct 20 '17 18:10 njpatel

@njpatel no, --directory doesn't work for me. I have the following setup:

# in ~/.zshrc
$GOPATH=/Users/adam/golang
# in /Users/adam/golang/src/github.com/myrepo/protobuf/myapp/service/myapp_service.proto
import "myapp/service/credentials/credentials.proto";

If I try to use grpcc with the absolute path to the proto, I get:

grpcc -i --proto $GOPATH/src/github.com/myrepo/protobuf/myapp/service/myapp_service.proto --address 127.0.0.1:8020

TypeError: Cannot read property 'ns' of null

If I try to cd to the directory first and then use the relative path, I get:

cd $GOPATH/src; grpcc -i --proto ./github.com/myrepo/protobuf/myapp/service/myapp_service.proto --address 127.0.0.1:8020

Error: failed to import '/Users/adam/golang/src/myapp/service/credentials/credentials.proto' in
  './github.com/myrepo/protobuf/myapp/service/myapp_service.proto': file not found

Which I guess is happening because of the relative path used in import "myapp/service/credentials/credentials.proto", and it's looking for /Users/adam/golang/src/myapp/service/credentials/credentials.proto instead of the correct path which is /Users/adam/golang/src/github.com/myrepo/protobuf/myapp/service/credentials/credentials.proto (the previous path is missing the github.com/myrepo/protobuf)

If I try using --directory, I get:

grpcc -i --proto ./github.com/myrepo/protobuf/myapp/service/myapp_service.proto --address 127.0.0.1:8020 --directory $GOPATH/src/github.com/myrepo/protobuf

TypeError: Cannot read property 'ns' of null

I've tried nearly every permutation of --directory value that I can think of, and they all result in the TypeError message.

adamcohen avatar Oct 21 '17 18:10 adamcohen

Bah, that's my fault, the usage of --directory isn't very clear. You can avoid the type error by dropping the full path to your proto (as the look up to your proto is relative to the directory):

grpcc -i --proto ./myapp/service/myapp_service.proto --address 127.0.0.1:8020 --directory $GOPATH/src/github.com/myrepo/protobuf

njpatel avatar Oct 22 '17 09:10 njpatel