nestjs / nest-cli

CLI tool for Nest applications 🍹
https://nestjs.com
Other
1.98k stars 395 forks source link

@fastify/view throwing error #2782

Closed Vilayat-Ali closed 3 weeks ago

Vilayat-Ali commented 3 weeks ago

Is there an existing issue for this?

Current behavior

The app fails to bootstrap and run.

Minimum reproduction code

https://github.com/Vilayat-Ali/eagle-nest/tree/problematic

Steps to reproduce

  1. Create an empty nest.js project
  2. Install ejs, @fastify/view

add this to main.ts file

app.setViewEngine({
    engine: {
      ejs,
    },
    templates: join(__dirname, 'templates'),
  })

And when using it for a controller like this

// lib
import { Controller, Get, Render } from "@nestjs/common";

@Controller("/admin")
export class AccountController {
    @Get("/login")
    @Render("home.ejs")
    login() {
        return {};
    }
}

and on running bun start:dev

The error


/mnt/projects/open-source/eagle-nest/node_modules/@nestjs/platform-fastify/node_modules/fastify/lib/pluginUtils.js:125
    throw new FST_ERR_PLUGIN_VERSION_MISMATCH(meta.name, requiredVersion, this.version)
          ^
FastifyError [Error]: fastify-plugin: @fastify/view - expected '5.x' fastify version, '4.28.1' is installed
    at Object.checkVersion (/mnt/projects/open-source/eagle-nest/node_modules/@nestjs/platform-fastify/node_modules/fastify/lib/pluginUtils.js:125:11)
    at Object.registerPlugin (/mnt/projects/open-source/eagle-nest/node_modules/@nestjs/platform-fastify/node_modules/fastify/lib/pluginUtils.js:148:16)
    at Boot.override (/mnt/projects/open-source/eagle-nest/node_modules/@nestjs/platform-fastify/node_modules/fastify/lib/pluginOverride.js:28:57)
    at Boot._loadPlugin (/mnt/projects/open-source/eagle-nest/node_modules/@nestjs/platform-fastify/node_modules/fastify/node_modules/avvio/boot.js:425:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  code: 'FST_ERR_PLUGIN_VERSION_MISMATCH',
  statusCode: 500
}

Expected behavior

It should have no issues (atleast when running the application)

Package version

10.4.5

NestJS version

10.4.6

Node.js version

Using bun instead (Bun v1.1.34)

In which operating systems have you tested?

Other

I am using bun (version: 1.1.34)

micalevisk commented 3 weeks ago

What if you use @fastify/view v8 instead?

kamilmysliwiec commented 3 weeks ago

Just use the compatible @fastify/view version.