Property 'setCookie' does not exist on type 'FastifyReply<ServerResponse>'.

See original GitHub issue

Installed fastify-cookie with npm install fastify-cookie.
Using VSCode.
fastify v.2.0.1 fastify-cookie v.3.0.2 error:

{
	"code": "2339",
	"message": "Property 'setCookie' does not exist on type 'FastifyReply<ServerResponse>'.",
	"source": "ts",
}

Code:

const fastifyCookie = require("fastify-cookie");
export const renderMiddleware = (fastify: FastifyInstance) => {
    fastify.register(fastifyCookie);
    fastify.post("/create-session-cookie", async (req, res) => {
       
        try {
            const sessionCookie = await thriftClient.createSession(
                "blabla",
                tokenExpDate,
                lastIp,
                tokenData,
                null
            );

            res.setCookie("sessionId", sessionCookie.sessionId, {}) < Throws error
                .status(200)
                .send(sessionCookie);
        } catch (e) {
            req.log.info(JSON.stringify(e));
            res.status(500).send(e);
            return;
        }
    });
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
evanshortisscommented, Jul 1, 2019

@colinmcparland I got more time to look into this and see the real issue.

Change:

const fastifyCookie = require("fastify-cookie");

to this:

import fastifyCookie = require("fastify-cookie");

Import will make TS import the typings.

1reaction
shunkicacommented, May 26, 2022

I have the same problem. Was this fixed?

TS2339: Property 'setCookie' does not exist on type 'FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>'.

"@nestjs/platform-fastify": "^8.4.5",
"fastify": "^3.29.0",
"fastify-cookie": "^5.7.0",
"typescript": "^4.7.2",

The package manager used does not affect the problem. I tried both npm and pnpm.

EDIT: Nevermind, I was using the wrong package because I was following NestJS docs where it states to use fastify-cookie. Needed to use @fastify/cookie

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'cookies' does not exist on type 'undefined'
Solution. Look at the code: Cypress.on('window:before:load', (win) => { // because this is called before any scripts // have loaded - the ga ......
Read more >
fastify-cookie - npm
Install · Repository · Homepage · Weekly Downloads · Version · License · Unpacked Size · Total Files.
Read more >
Cookies | NestJS - A progressive Node.js framework
These properties are name value pairs of the cookie name to cookie value. When secret is provided, this module will unsign and validate...
Read more >
Document.cookie - Web APIs | MDN
The Document property cookie lets you read and write cookies associated with the document. It serves as a getter and setter for the...
Read more >
setcookie - Manual - PHP
If output exists prior to calling this function, setcookie() will fail and return false . ... This does not indicate whether the user...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found