I’m kinda new to backend development and I’m making a simple backend server with fastify, typescript, postgresql and prisma and docker. everything works, but now i want to add swagger api documentation but came across a problem.
heres my index.ts:
import fastify from "fastify";
import inventoryRoutes from "./routes/inventoryRoutes";
import fastifySwagger from "@fastify/swagger";
import fastifySwaggerUi from "@fastify/swagger-ui";
const server = fastify();
const swaggerOptions = {
swagger: {
info: {
title: "My Title",
description: "My Description.",
version: "1.0.0",
},
host: "localhost",
schemes: ["http", "https"],
consumes: ["application/json"],
produces: ["application/json"],
tags: [{ name: "Default", description: "Default" }],
},
};
const swaggerUiOptions = {
routePrefix: "/docs",
exposeRoute: true,
};
server.register(fastifySwagger, swaggerOptions);
server.register(fastifySwaggerUi, swaggerUiOptions);
// Register routes
inventoryRoutes(server);
// Start server
server.listen({ port: 8080, host: "0.0.0.0" }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log(`Server listening at ${address}`);
});
when running docker compose up, it returns this error:
inventory-api-1 | src/index.ts(3,28): error TS2307: Cannot find module '@fastify/swagger' or its corresponding type declarations.
inventory-api-1 | src/index.ts(4,30): error TS2307: Cannot find module '@fastify/swagger-ui' or its corresponding type declarations.
Even though its installed and i can see them in my package.json and it doesnt show an error in IDE. where did i go wrong?