nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.9k stars 7.55k forks source link

grpcPackage.loadPackageDefinition is not a function #1473

Closed kmturley closed 5 years ago

kmturley commented 5 years ago

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

Running the sample gRPC project from: https://github.com/nestjs/nest/tree/master/sample/04-grpc

You get the error:

[Nest] 62903   - 2019-1-26 17:43:57   [NestFactory] Starting Nest application...
[Nest] 62903   - 2019-1-26 17:43:57   [InstanceLoader] ApplicationModule dependencies initialized +10ms
[Nest] 62903   - 2019-1-26 17:43:57   [InstanceLoader] HeroModule dependencies initialized +0ms
[Nest] 62903   - 2019-1-26 17:43:57   [NestMicroservice] Nest microservice successfully started +103ms
[Nest] 62903   - 2019-1-26 17:43:57   [Server] grpcPackage.loadPackageDefinition is not a function +14ms
Error: The invalid .proto definition (file not found)
    at ServerGrpc.loadProto (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:140:39)
    at ServerGrpc.bindEvents (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:33:34)
    at ServerGrpc.start (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:28:20)
    at ServerGrpc.listen (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:25:20)
    at NestMicroservice.listen (nest/sample/04-grpc/node_modules/@nestjs/microservices/nest-microservice.js:81:21)
    at Promise (nest/sample/04-grpc/node_modules/@nestjs/core/nest-application.js:275:32)
    at new Promise (<anonymous>)
    at listenToPromise (nest/sample/04-grpc/node_modules/@nestjs/core/nest-application.js:274:16)
    at Array.map (<anonymous>)
    at NestApplication.startAllMicroservices (nest/sample/04-grpc/node_modules/@nestjs/core/nest-application.js:152:40)
(node:62903) UnhandledPromiseRejectionWarning: Error: The invalid .proto definition (file not found)
    at ServerGrpc.loadProto (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:140:39)
    at ServerGrpc.bindEvents (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:33:34)
    at ServerGrpc.start (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:28:20)
    at ServerGrpc.listen (nest/sample/04-grpc/node_modules/@nestjs/microservices/server/server-grpc.js:25:20)
    at NestMicroservice.listen (nest/sample/04-grpc/node_modules/@nestjs/microservices/nest-microservice.js:81:21)
    at Promise (nest/sample/04-grpc/node_modules/@nestjs/core/nest-application.js:275:32)
    at new Promise (<anonymous>)
    at listenToPromise (nest/sample/04-grpc/node_modules/@nestjs/core/nest-application.js:274:16)
    at Array.map (<anonymous>)
    at NestApplication.startAllMicroservices (nest/sample/04-grpc/node_modules/@nestjs/core/nest-application.js:152:40)
(node:62903) 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: 4)
(node:62903) [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.

Expected behavior

Running the local server correctly

Minimal reproduction of the problem with instructions

Clone the sample gRPC project at: https://github.com/nestjs/nest/tree/master/sample/04-grpc

Then run the setup commands:

npm install
npm start

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

Should have working sample projects for everyone to easily adopt NestJS.

How to fix

Upgrade the package.json versions to make it work:

{
  "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.3.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"
  }
}

Environment

Nest: 5.8.0
Node: 8.12.0
Npm: 6.4.1
Platform: MacOS 10.13.6
kamilmysliwiec commented 5 years ago

Does this issue still occur in 5.7.0?

kmturley commented 5 years ago

Still occurring, you need to:

rm package-lock.json
npm install

then recommit the new package-lock.json. If I do those steps then it works!

I have some additional feedback about getting the gRPC server talking to a browser client, and getting Nest REST API running on AppEngine. But will save those for separate issues :)

kamilmysliwiec commented 5 years ago

Fixed in the latest versions of all packages (grpc, @grpc/proto-loader and @nestjs/microservices)

lock[bot] commented 4 years ago

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.