axe-me / vite-plugin-node

Vite plugin to run your node dev server with HMR!
986 stars 46 forks source link

Nest.js + Fastify: No driver (HTTP) has been selected. #101

Closed simplenotezy closed 11 months ago

simplenotezy commented 11 months ago

Aparently https://github.com/axe-me/vite-plugin-node/issues/30 should be supported, but we're getting error:

[Nest] 89486  - 10/23/2023, 1:55:00 PM   ERROR [PackageLoader] No driver (HTTP) has been selected. In order to take advantage of the default driver, please, ensure to install the "@nestjs/platform-express" package ($ npm install @nestjs/platform-express).

This is our viteconfig:

/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'vite';
import { VitePluginNode } from 'vite-plugin-node';

export default defineConfig({
  // ...vite configures
  server: {
    // vite server configs, for details see \[vite doc\](https://vitejs.dev/config/#server-host)
    port: 3000,
  },
  plugins: [
    ...VitePluginNode({
      // Nodejs native Request adapter
      // currently this plugin support 'express', 'nest', 'koa' and 'fastify' out of box,
      // you can also pass a function if you are using other frameworks, see Custom Adapter section
      adapter: 'nest',
      // tell the plugin where is your project entry
      appPath: './src/main.ts',
      // Optional, default: 'esbuild'
      // The TypeScript compiler you want to use
      // by default this plugin is using vite default ts compiler which is esbuild
      // 'swc' compiler is supported to use as well for frameworks
      // like Nestjs (esbuild dont support 'emitDecoratorMetadata' yet)
      // you need to INSTALL `@swc/core` as dev dependency if you want to use swc
      tsCompiler: 'swc',
    }),
  ],
  optimizeDeps: {
    // Vite does not work well with optionnal dependencies,
    // mark them as ignored for now
    exclude: [
      '@nestjs/microservices',
      '@nestjs/websockets',
      'cache-manager',
      'class-transformer',
      'class-validator',
      'fastify-swagger',
      'fsevents',

      '@nestjs/platform-fastify',
      'fastify',
      'class-transformer/storage',
      '@fastify/view',

      // GraphQL dependencies.
      '@apollo/subgraph',
      'ts-morph',
      'apollo-server-core',
      '@apollo/gateway',
      'point-of-view',
    ],
  },
});

This is our dependencies:

@apollo/server
@as-integrations/fastify
@aws-sdk/client-s3
@blazity/nest-file-fastify
@bull-board/api
@bull-board/fastify
@bull-board/nestjs
@faker-js/faker
@fastify/basic-auth
@fastify/multipart
@google-cloud/storage
@nestjs-modules/mailer
@nestjs/apollo
@nestjs/bullmq
@nestjs/common
@nestjs/config
@nestjs/core
@nestjs/cqrs
@nestjs/graphql
@nestjs/jwt
@nestjs/platform-fastify
@nestjs/schedule
@nestjs/terminus
@nestjs/typeorm
@sentry/integrations
@sentry/node
@sentry/tracing
@slack/bolt
@songkeys/nestjs-redis
@songkeys/nestjs-redis-health
@types/bcryptjs
@types/body-parser
@types/jsonwebtoken
@willsoto/nestjs-prometheus
apollo-server-core
bcryptjs
blurhash
bullmq
chalk
class-transformer
class-validator
cli-progress
country-data
dataloader
date-fns
date-fns-tz
emoji-regex
fastify
firebase-admin
geo-tz
geojson
get-port
google-libphonenumber
graphql
graphql-depth-limit
graphql-query-complexity
graphql-redis-subscriptions
graphql-type-json
h3-js
i18n
image-size
intercom-client
ioredis
libphonenumber-js
lodash
migrate
mjml
nest-commander
nest-raven
nestjs-slack-listener
newrelic
node-fetch
node-geocoder
p-limit
pg
prom-client
rand-token
reflect-metadata
rimraf
rxjs
sharp
source-map-support
ts-mockito
tslib
typeorm
typeorm-naming-strategies
unique-names-generator
uuid
simplenotezy commented 11 months ago

Not sure if it's related? https://github.com/nestjs/nest/issues/1609

simplenotezy commented 11 months ago

Oh, I was missing this part (in main.ts):


-export const viteNodeApp = NestFactory.create(AppModule);
+export const viteNodeApp = NestFactory.create(AppModule, new FastifyAdapter());