Error @fastify/static - expected '^4.23.0' fastify version, '4.18.0' is installed fastify-plugin: @fastify/static - expected '^4.23.0' fastify version, '4.18.0'
badrus123 opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
- npm install
- npm run:dev / nest start --watch
- see error
Minimum reproduction code
https://github.com/badrus123/nestjs-fastify
Steps to reproduce
- npm install
- npm run:dev / nest start --watch
- check console log
Expected behavior
i think upgrade your package @fastify/fastify-static for solving this problem
Package version
6.2.1
NestJS version
9.3.9
Node.js version
16.14.2
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
I have errors like above
{"code":"FST_ERR_PLUGIN_VERSION_MISMATCH","name":"FastifyError","statusCode":500,"message":"fastify-plugin: @fastify/static - expected '^4.23.0' fastify version, '4.18.0' is installed fastify-plugin: @fastify/static - expected '^4.23.0' fastify version, '4.18.0' is installed","level":"fatal","stack":"FastifyError: fastify-plugin: @fastify/static - expected '^4.23.0' fastify version, '4.18.0' is installed\n at Object.checkVersion (/node_modules/fastify/lib/pluginUtils.js:121:11)\n at Object.registerPlugin (/node_modules/fastify/lib/pluginUtils.js:136:16)\n at Boot.override (/node_modules/fastify/lib/pluginOverride.js:28:57)\n at Plugin.exec (/node_modules/avvio/plugin.js:79:33)\n at Boot.loadPlugin (/node_modules/avvio/plugin.js:272:10)\n at processTicksAndRejections (node:internal/process/task_queues:83:21)","timestamp":"2023-09-14T10:38:13.224Z","serverName":"service-verification-54c6bdbb7c-dqlnc","serviceName":"service-verification","environment":"staging","sourceLocation":"(dist/main.js:61)"}
and my code like this
import {SwaggerModule, DocumentBuilder} from '@nestjs/swagger';
import {NestFastifyApplication, FastifyAdapter} from '@nestjs/platform-fastify';
import {v4 as uuidv4} from 'uuid';
import {HttpExceptionFilter} from './utility/filter/http-exception.filter';
import {BaseResponseInterceptor} from './utility/interceptor/base-response.interceptor';
import {AppModule} from './app.module';
import {ValidationPipe} from '@nestjs/common';
async function bootstrap() {
try {
const PORT = process.env.PORT;
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({
logger: true,
genReqId: () => uuidv4(),
}),
);
app.useGlobalPipes(new ValidationPipe()); // enable ValidationPipe`
app.useGlobalInterceptors(new BaseResponseInterceptor());
app.useGlobalFilters(new HttpExceptionFilter());
app.enableCors({origin: '*'});
const config = new DocumentBuilder()
.setTitle('External API')
.setDescription('Service for Authentication with Header key')
.setVersion('1.0')
.addBearerAuth(
{
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
name: 'JWT',
description: 'Enter JWT token',
in: 'header',
},
'JWT', // This name here is important for matching up with @ApiBearerAuth() in your controller!
)
// .addServer('/api/v1/ex')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('/api-docs', app, document);
await app.listen(PORT, '0.0.0.0');
} catch (error) {
// console.log(error);
}
}
bootstrap();
I think the problem when I use Fastify and @nest/swagger in my project
me to
+1, they just decided to enforce a specific version fastify/fastify-static@e0a816e
6.11.2 was added for @fastify/fastify-static which is now keeping the backwards compatibility. The PR you opened won't fix it since it's a devDependency and fastify should be actually be updated in the @nestjs/platform-fastify package. Therefore the fix should be in your project by updating to 6.11.2 (which is then used as a peerDependecy in the other packages) (or using the 6.11.0)
solve thanks a lot @DanelGorgan