首页 > 解决方案 > 在 nuxtjs 中使用 nestjs

问题描述

为什么这不起作用https://github.com/Mitch-i/nuxt_nest

错误 [ExceptionsHandler] 无法读取未定义的属性“findOne”类型错误:无法读取未定义的属性“findOne”

[Nest] 16671 - 09/21/2021,下午 5:00:55 错误 [ExceptionsHandler] 装饰类属性失败。请确保proposal-class-properties 已启用并在装饰器转换后运行。

但仅在我仅在正常模式下启动 nesjs 服务器时才有效(不像 nuxtjs 温和软件)。

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

async function bootstrap () {
  const app = await NestFactory.create<NestFastifyApplication>(
    AppModule,
    new FastifyAdapter({ ignoreTrailingSlash: true, logger: true })
  )

  await app.init()

  const fastify = app.getHttpAdapter().getInstance()

  await fastify.ready()

  return function (req: Request, res: Response) {
    fastify.server.emit('request', req, res)
  }
}

export default bootstrap

import { Module } from '@nestjs/common'
import { SequelizeModule } from '@nestjs/sequelize'
import { UsersModule } from './users/users.module'

@Module({
  imports: [
    SequelizeModule.forRoot({
      dialect: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'user',
      password: 'password',
      database: 'database',
      autoLoadModels: true,
      synchronize: true
    }),
    UsersModule
  ]
})
export class AppModule {}

import bootstrap from './server/main'

export default async () => ({
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: 'nuxt',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' },
      { name: 'format-detection', content: 'telephone=no' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
  ],

  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [
  ],

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/typescript
    '@nuxt/typescript-build',
  ],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
  ],

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
  },

  serverMiddleware: [
    { path: '/api', handler: await bootstrap() }
  ]
})

标签: nuxt.jsnestjs

解决方案


推荐阅读