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

Can't get Fastify JS starter to work #4108

Closed vinkaga closed 4 years ago

vinkaga commented 4 years ago

Bug Report

Created JS sample from cli. Ran npm run start, runs correctly. Modified for Fastify by changing main.js as shown below. Then run fails with error TypeError: app.listen is not a function.

Current behavior

~/d/neserver (master|…) $ npm run start

> neserver@0.0.1 start /Users/vagarwal/dev/neserver
> babel-node index.js

(node:1892) UnhandledPromiseRejectionWarning: TypeError: app.listen is not a function
    at _callee$ (/Users/vagarwal/dev/neserver/src/main.js:13:13)
    at tryCatch (/Users/vagarwal/dev/neserver/node_modules/regenerator-runtime/runtime.js:45:40)
    at Generator.invoke [as _invoke] (/Users/vagarwal/dev/neserver/node_modules/regenerator-runtime/runtime.js:271:22)
    at Generator.prototype.<computed> [as next] (/Users/vagarwal/dev/neserver/node_modules/regenerator-runtime/runtime.js:97:21)
    at asyncGeneratorStep (/Users/vagarwal/dev/neserver/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
    at _next (/Users/vagarwal/dev/neserver/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:1892) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1892) [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.

Main.js after modification

import { NestFactory } from '@nestjs/core';
import {
  FastifyAdapter,
  NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
      new FastifyAdapter()
  );
  await app.listen(3000);
}
bootstrap();

Expected behavior

~/d/n/s/10-fastify (master|✔) $ npm run start

nest-typescript-starter@1.0.0 start /Users/vagarwal/dev/nest/sample/10-fastify nest start

[Nest] 97785 - 02/19/2020, 4:21:26 PM [NestFactory] Starting Nest application... [Nest] 97785 - 02/19/2020, 4:21:26 PM [InstanceLoader] AppModule dependencies initialized +15ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [InstanceLoader] CoreModule dependencies initialized +1ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [InstanceLoader] CatsModule dependencies initialized +0ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [RoutesResolver] CatsController {/cats}: +14ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [RouterExplorer] Mapped {/, POST} route +4ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [RouterExplorer] Mapped {/, GET} route +1ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [RouterExplorer] Mapped {/:id, GET} route +1ms [Nest] 97785 - 02/19/2020, 4:21:26 PM [NestApplication] Nest application successfully started +3ms

Environment


Nest version: 6.14.2


For Tooling issues:
- Node version: v13.8.0
- Platform:  Mac

Others:

jmcdo29 commented 4 years ago

If you are using JavaScript instead of Typescript for development then you shouldn't have generics in your code anywhere. This is a working main.js file for Fastify on Linux Mint 19.1 with Node 13.7.

import { NestFactory } from '@nestjs/core';
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, new FastifyAdapter());
  await app.listen(3000);
}
bootstrap();
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.