Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gRPC] TypeError: Cannot read property 'service' of null #1469

Closed
VincentSurelle opened this issue Jan 24, 2019 · 4 comments
Closed

[gRPC] TypeError: Cannot read property 'service' of null #1469

VincentSurelle opened this issue Jan 24, 2019 · 4 comments

Comments

@VincentSurelle
Copy link

Hi everyone ;)

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

On gRPC microservice startup, Unhandled exception is thrown :

[nodemon] starting `ts-node -r tsconfig-paths/register src/main.ts`
[Nest] 44151   - 1/24/2019, 5:05:24 PM   [NestFactory] Starting Nest application...
[Nest] 44151   - 1/24/2019, 5:05:24 PM   [InstanceLoader] CustomersModule dependencies initialized +0ms
[Nest] 44151   - 1/24/2019, 5:05:24 PM   [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 44151   - 1/24/2019, 5:05:24 PM   [NestMicroservice] Nest microservice successfully started +194ms
(node:44151) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'service' of null
    at ServerGrpc.collectDeepServices (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:195:24)
    at ServerGrpc.collectDeepServices (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:208:14)
    at ServerGrpc.collectDeepServices (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:208:14)
    at ServerGrpc.collectDeepServices (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:208:14)
    at ServerGrpc.collectDeepServices (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:208:14)
    at ServerGrpc.getServiceNames (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:62:10)
    at ServerGrpc.bindEvents (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:44:35)
    at ServerGrpc.start (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:29:16)
    at ServerGrpc.listen (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/server/server-grpc.js:26:16)
    at NestMicroservice.listen (/Users/vincent/Workspace/customers-dal/node_modules/@nestjs/microservices/nest-microservice.js:81:21)
(node:44151) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:44151) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[nodemon] clean exit - waiting for changes before restart

Expected behavior

Normal startup ? 😄

Minimal reproduction of the problem with instructions

Here is my main.ts :

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Transport } from '@nestjs/common/enums/transport.enum';
import { join } from 'path';

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.GRPC,
    options: {
      package: 'customers',
      protoPath: join(__dirname, './proto/customers.proto'),
    },
  });
  await app.listenAsync();
}
bootstrap();

And here is my .proto file :

syntax = "proto3";

package customers;

import "google/protobuf/empty.proto";

service CustomersService {
  rpc AddOne (Customer) returns (Customer) {}
  rpc GetOne (CustomerById) returns (Customer) {}
  rpc GetAll (google.protobuf.Empty)  returns (Customers) {}
  rpc UpdateOne (Customer) returns (Customer) {}
  rpc DeleteOne (CustomerById) returns (CustomerById) {}
}

message Address {
  string addressLine1 = 1;
  string addressLine2 = 2;
  string addressLine3 = 3;
  string addressLine4 = 4;
  string zipcode = 5;
  string city = 6;
  string state = 7;
  string country = 8;
}

message Customer {
  int32 id = 1;
  string name = 2;
  string email = 3;
  string phone = 4;
  string website = 5;
  string number = 6;
  Address address = 8;
  string logo = 12;
  string banner = 13;
}

message CustomerById {
  int32 id = 1;
}

message Customers {
  repeated Customer customers = 1;
}

Apparently, the problem come from this line (server-grpc.js) :

const isServiceDefined = !shared_utils_1.isUndefined(deepDefinition.service);

I tried to console.log some thing to help debugging :

key: options
deepDefinition: null
nameExtended: Address.type.field.0.options

What is the motivation / use case for changing the behavior?

Environment


 "@nestjs/common": "^5.4.0",
 "@nestjs/core": "^5.4.0",
 "@nestjs/microservices": "^5.6.2",
For Tooling issues:
- Node version: 11.7.0
- Platform:  Mac

Others:
"@grpc/proto-loader": "^0.4.0",
"grpc": "^1.18.0",

Thanks for any help provided :)

@VincentSurelle
Copy link
Author

It works with "@grpc/proto-loader": "^0.3.0"

@kmturley
Copy link

Equally if you take the sample project:
https://github.com/nestjs/nest/tree/master/sample/04-grpc

It has errors when running:

[Nest] 62903   - 2019-1-26 17:43:57   [Server] grpcPackage.loadPackageDefinition is not a function +14ms
Error: The invalid .proto definition (file not found)

If you upgrade all the packages to latest versions:

{
  "name": "nest-typescript-starter",
  "version": "1.0.0",
  "description": "Nest TypeScript starter repository",
  "license": "MIT",
  "scripts": {
    "start": "ts-node src/main.ts",
    "prestart:prod": "tsc",
    "start:prod": "node dist/main.js"
  },
  "dependencies": {
    "@grpc/proto-loader": "^0.4.0",
    "@nestjs/common": "^5.3.7",
    "@nestjs/core": "^5.3.7",
    "@nestjs/microservices": "^5.3.7",
    "@nestjs/testing": "^5.3.7",
    "@nestjs/websockets": "^5.3.7",
    "class-transformer": "^0.1.7",
    "class-validator": "^0.7.2",
    "grpc": "^1.10.0",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^6.1.0",
    "typescript": "^2.8.0"
  },
  "devDependencies": {
    "@types/node": "^7.0.41",
    "ts-node": "^6.0.0",
    "tslint": "^5.9.1"
  }
}

you get the same error:
(node:44151) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'service' of null

but downgrading proto-loader worked:
npm install @grpc/proto-loader@0.3.0

@kamilmysliwiec
Copy link
Member

Fixed in 5.7.0

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants