Skip to content

Property 'get' does not exist on type 'FastifyInstance' #1077

Open

Description

@omarpanait

You have already researched for similar issues?

I searched for the problem and tried most solutions given without success.

What are you trying to achieve, or the steps to reproduce?

I followed the documentation for installing Fastify with Typescript but I keep getting the type error.

{
  "name": "fst",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "tsc -p tsconfig.json",
    "start": "node ./dist/server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^5.2.1"
  },
  "devDependencies": {
    "@tsconfig/node18": "^18.2.4",
    "@types/node": "^22.10.5",
    "typescript": "^5.7.2"
  }
}
{
    "extends": "@tsconfig/node18/tsconfig.json",
    "compilerOptions": {
        "outDir": "./dist",
        "lib": ["es2018"],
        "target": "es2018"
    }

}
import fastify from 'fastify'

const server = fastify()

server.get('/ping', async (request, reply) => {
  return 'pong\n'
})

server.listen({ port: 8080 }, (err, address) => {
  if (err) {
    console.error(err)
    process.exit(1)
  }
  console.log(`Server listening at ${address}`)
})


server.listen({port: 3333})

What was the result you received?

Property 'get' does not exist on type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...> & { ...; }'.ts(2339)

What did you expect?

To not show the error

Context

  • node version: 18.19.1
  • fastify version: 5.2.1
  • os: Ubuntu 24.04.1

I also tried inside Docker with node:23.1-bullseye and I get the same error.

Screenshot from 2025-01-07 04-29-56

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions